<!DOCTYPE html>
<!-- saved from url=(0056)http://www.linux178.com/storage/fastdfs-nginx-cache.html -->
<html class="no-js"><!--<![endif]--><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
    <meta name="renderer" content="webkit">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>FastDFS + Nginx 反向代理缓存 安装与配置 - The Soul of Linux</title>

    <!-- 使用url函数转换相关路径 -->
    <link rel="stylesheet" href="./FastDFS + Nginx 反向代理缓存 安装与配置 - The Soul of Linux_files/normalize.css">
    <link rel="stylesheet" href="./FastDFS + Nginx 反向代理缓存 安装与配置 - The Soul of Linux_files/grid.css">
    <link rel="stylesheet" href="./FastDFS + Nginx 反向代理缓存 安装与配置 - The Soul of Linux_files/style.css">

    <!--[if lt IE 9]>
    <script src="http://www.linux178.com/admin/js/html5shiv.js"></script>
    <script src="http://www.linux178.com/admin/js/respond.js"></script>
    <![endif]-->

    <!-- 通过自有函数输出HTML头部信息 -->
    <link rel="stylesheet" type="text/css" href="./FastDFS + Nginx 反向代理缓存 安装与配置 - The Soul of Linux_files/dark.css"><meta name="description" content="操作系统  CentOS release 6.5 (Final) 64nginx相关软件nginx-1.4.7 下载地址: http://nginx.org/en/download.html#ngin...">
<meta name="keywords" content="fastdfs,nginx,分布式存储,分布式,缓存">
<meta name="generator" content="Typecho 1.0/14.10.10">
<meta name="template" content="default">
<link rel="pingback" href="http://www.linux178.com/action/xmlrpc">
<link rel="EditURI" type="application/rsd+xml" title="RSD" href="http://www.linux178.com/action/xmlrpc?rsd">
<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="http://www.linux178.com/action/xmlrpc?wlw">
<link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="http://www.linux178.com/feed/storage/fastdfs-nginx-cache.html">
<link rel="alternate" type="application/rdf+xml" title="RSS 1.0" href="http://www.linux178.com/feed/rss/storage/fastdfs-nginx-cache.html">
<link rel="alternate" type="application/atom+xml" title="ATOM 1.0" href="http://www.linux178.com/feed/atom/storage/fastdfs-nginx-cache.html">
<script type="text/javascript">
//<![CDATA[
var TypechoComment = {
    dom : function (id) {
        return document.getElementById(id);
    },
    
    create : function (tag, attr) {
        var el = document.createElement(tag);
        
        for (var key in attr) {
            el.setAttribute(key, attr[key]);
        }
        
        return el;
    },

    reply : function (cid, coid) {
        var comment = this.dom(cid), parent = comment.parentNode,
            response = this.dom('respond-post-127'), input = this.dom('comment-parent'),
            form = 'form' == response.tagName ? response : response.getElementsByTagName('form')[0],
            textarea = response.getElementsByTagName('textarea')[0];

        if (null == input) {
            input = this.create('input', {
                'type' : 'hidden',
                'name' : 'parent',
                'id'   : 'comment-parent'
            });

            form.appendChild(input);
        }
        
        input.setAttribute('value', coid);

        if (null == this.dom('comment-form-place-holder')) {
            var holder = this.create('div', {
                'id' : 'comment-form-place-holder'
            });
            
            response.parentNode.insertBefore(holder, response);
        }

        comment.appendChild(response);
        this.dom('cancel-comment-reply-link').style.display = '';
        
        if (null != textarea && 'text' == textarea.name) {
            textarea.focus();
        }
        
        return false;
    },

    cancelReply : function () {
        var response = this.dom('respond-post-127'),
        holder = this.dom('comment-form-place-holder'), input = this.dom('comment-parent');

        if (null != input) {
            input.parentNode.removeChild(input);
        }

        if (null == holder) {
            return true;
        }

        this.dom('cancel-comment-reply-link').style.display = 'none';
        holder.parentNode.insertBefore(response, holder);
        return false;
    }
}
//]]>
</script></head>
<body>
<!--[if lt IE 8]>
    <div class="browsehappy">当前网页 <strong>不支持</strong> 你正在使用的浏览器. 为了正常的访问, 请 <a href="http://browsehappy.com/">升级你的浏览器</a>.</div>
<![endif]-->

<header id="header" class="clearfix">
    <div class="container">
        <div class="colgroup">
            <div class="site-name col-mb-12 col-9">
                <a id="logo" href="http://www.linux178.com/">
                                        The Soul of Linux                </a>
        	    <p class="description">Thinking in DevOps</p>
            </div>
            <div class="site-search col-3 kit-hidden-tb">
                <form id="search" method="post" action="http://www.linux178.com/storage/" role="search">
                    <label for="s" class="sr-only">搜索关键字</label>
                    <input type="text" name="s" class="text" placeholder="输入关键字搜索">
                    <button type="submit" class="submit">搜索</button>
                </form>
            </div>
            <div class="col-mb-12">
                <nav id="nav-menu" class="clearfix" role="navigation">
                    <a href="http://www.linux178.com/">首页</a>
                                                            <a href="http://www.linux178.com/github.html" title="GitHub项目">GitHub项目</a>
                                        <a href="http://www.linux178.com/easyxmsjava.html" title="EasyXMS(Java)">EasyXMS(Java)</a>
                                        <a href="http://www.linux178.com/easyxms.html" title="EasyXMS(Python)">EasyXMS(Python)</a>
                                        <a href="http://www.linux178.com/nginxlog.html" title="WEB日志分析脚本">WEB日志分析脚本</a>
                                        <a href="http://www.linux178.com/about.html" title="关于">关于</a>
                                        <a href="http://www.linux178.com/youlink.html" title="友链">友链</a>
                                    </nav>
            </div>
        </div><!-- end .colgroup -->
    </div>
</header><!-- end #header -->
<div id="body">
    <div class="container">
        <div class="colgroup">

    
    

<div class="col-mb-12 col-8" id="main" role="main">
    <article class="post">
        <h1 class="post-title"><a href="./FastDFS + Nginx 反向代理缓存 安装与配置 - The Soul of Linux_files/FastDFS + Nginx 反向代理缓存 安装与配置 - The Soul of Linux.html">FastDFS + Nginx 反向代理缓存 安装与配置</a></h1>
        <ul class="post-meta">
            <li>作者：斯巴达克斯</li>
            <li>时间：March 26, 2015</li>
            <li>分类：<a href="http://www.linux178.com/category/storage/">存储</a></li>
        </ul>
        <div class="post-content">
            <p>操作系统  CentOS release 6.5 (Final) 64</p>

<h2>nginx相关软件</h2>

<p>nginx-1.4.7 下载地址: <a rel="nofollow" href="http://nginx.org/en/download.html#">http://nginx.org/en/download.html#</a><br>
nginx清除缓存模块 ngx_cache_purge-2.1  <a rel="nofollow" href="http://labs.frickle.com/nginx_ngx_cache_purge/">http://labs.frickle.com/nginx_ngx_cache_purge/</a><br>
pcre-8.36  <a rel="nofollow" href="ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.36.tar.gz">ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.36.tar.gz</a><br>
zlib库 <a rel="nofollow" href="http://zlib.net/zlib-1.2.8.tar.gz">http://zlib.net/zlib-1.2.8.tar.gz</a></p>

<h2>FastDFS相关软件</h2>

<p>FastDFS_v5.04<br>
<a rel="nofollow" href="http://sourceforge.net/projects/fastdfs/files">http://sourceforge.net/projects/fastdfs/files</a></p>

<p>FastDFS Nginx Module 1.16<br>
<a rel="nofollow" href="http://sourceforge.net/projects/fastdfs/files/FastDFS%20Nginx%20Module%20Source%20Code/">http://sourceforge.net/projects/fastdfs/files/FastDFS%20Nginx%20Module%20Source%20Code/</a></p>

<p>libfastcommon<br>
<a rel="nofollow" href="https://github.com/happyfish100/libfastcommon.git">https://github.com/happyfish100/libfastcommon.git</a></p>

<h2>拓扑图</h2>

<p><img src="./FastDFS + Nginx 反向代理缓存 安装与配置 - The Soul of Linux_files/4088758394.jpg" alt="2dd42041-2aba-4a82-8a6b-b48dac7c0e86.jpg"></p>

<!--more-->

<h1>二、tracker的安装与配置</h1>

<h4>1.安装</h4>

<p>以下操作是在 tracker 10.10.10.124上操作</p>

<p>通过rz工具，把软件上传到/usr/local/src目录下，如果没有rz工具，可以使用 yum -y install lrzsz 安装</p>

<pre><code class="brainfuck">
<span class="title">[</span><span class="comment">root@tracker</span> <span class="comment">src</span><span class="title">]</span><span class="comment">#</span> <span class="comment">ls</span>
<span class="comment">FastDFS_v5</span><span class="string">.</span><span class="comment">04</span><span class="string">.</span><span class="comment">tar</span><span class="string">.</span><span class="comment">gz</span>
<span class="title">[</span><span class="comment">root@tracker</span> <span class="comment">src</span><span class="title">]</span><span class="comment">#</span> <span class="comment">tar</span> <span class="comment">xf</span> <span class="comment">FastDFS_v5</span><span class="string">.</span><span class="comment">04</span><span class="string">.</span><span class="comment">tar</span><span class="string">.</span><span class="comment">gz</span> 
<span class="title">[</span><span class="comment">root@tracker</span> <span class="comment">src</span><span class="title">]</span><span class="comment">#</span> <span class="comment">cd</span> <span class="comment">FastDFS</span>
<span class="title">[</span><span class="comment">root@tracker</span> <span class="comment">FastDFS</span><span class="title">]</span><span class="comment">#</span> <span class="comment">ll</span>
<span class="comment">总用量</span> <span class="comment">132</span>
<span class="comment">drwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span><span class="string">.</span> <span class="comment">3</span> <span class="comment">8980</span> <span class="comment">users</span>  <span class="comment">4096</span> <span class="comment">9月</span>  <span class="comment">21</span> <span class="comment">22:14</span> <span class="comment">client</span>
<span class="comment">drwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span><span class="string">.</span> <span class="comment">2</span> <span class="comment">8980</span> <span class="comment">users</span>  <span class="comment">4096</span> <span class="comment">9月</span>  <span class="comment">21</span> <span class="comment">22:14</span> <span class="comment">common</span>
<span class="comment">drwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span><span class="string">.</span> <span class="comment">2</span> <span class="comment">8980</span> <span class="comment">users</span>  <span class="comment">4096</span> <span class="comment">9月</span>  <span class="comment">21</span> <span class="comment">22:14</span> <span class="comment">conf</span>
<span class="literal">-</span><span class="comment">rw</span><span class="literal">-</span><span class="comment">r</span><span class="literal">-</span><span class="literal">-</span><span class="comment">r</span><span class="literal">-</span><span class="literal">-</span><span class="string">.</span> <span class="comment">1</span> <span class="comment">8980</span> <span class="comment">users</span> <span class="comment">35067</span> <span class="comment">9月</span>  <span class="comment">21</span> <span class="comment">22:14</span> <span class="comment">COPYING</span><span class="literal">-</span><span class="comment">3_0</span><span class="string">.</span><span class="comment">txt</span>
<span class="literal">-</span><span class="comment">rw</span><span class="literal">-</span><span class="comment">r</span><span class="literal">-</span><span class="literal">-</span><span class="comment">r</span><span class="literal">-</span><span class="literal">-</span><span class="string">.</span> <span class="comment">1</span> <span class="comment">8980</span> <span class="comment">users</span>  <span class="comment">2802</span> <span class="comment">9月</span>  <span class="comment">21</span> <span class="comment">22:14</span> <span class="comment">fastdfs</span><span class="string">.</span><span class="comment">spec</span>
<span class="literal">-</span><span class="comment">rw</span><span class="literal">-</span><span class="comment">r</span><span class="literal">-</span><span class="literal">-</span><span class="comment">r</span><span class="literal">-</span><span class="literal">-</span><span class="string">.</span> <span class="comment">1</span> <span class="comment">8980</span> <span class="comment">users</span> <span class="comment">31224</span> <span class="comment">9月</span>  <span class="comment">21</span> <span class="comment">22:14</span> <span class="comment">HISTORY</span>
<span class="comment">drwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span><span class="string">.</span> <span class="comment">2</span> <span class="comment">8980</span> <span class="comment">users</span>  <span class="comment">4096</span> <span class="comment">9月</span>  <span class="comment">21</span> <span class="comment">22:14</span> <span class="comment">init</span><span class="string">.</span><span class="comment">d</span>
<span class="literal">-</span><span class="comment">rw</span><span class="literal">-</span><span class="comment">r</span><span class="literal">-</span><span class="literal">-</span><span class="comment">r</span><span class="literal">-</span><span class="literal">-</span><span class="string">.</span> <span class="comment">1</span> <span class="comment">8980</span> <span class="comment">users</span>  <span class="comment">7755</span> <span class="comment">9月</span>  <span class="comment">21</span> <span class="comment">22:14</span> <span class="comment">INSTALL</span>
<span class="literal">-</span><span class="comment">rwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span><span class="string">.</span> <span class="comment">1</span> <span class="comment">8980</span> <span class="comment">users</span>  <span class="comment">5735</span> <span class="comment">9月</span>  <span class="comment">21</span> <span class="comment">22:14</span> <span class="comment">make</span><span class="string">.</span><span class="comment">sh</span>
<span class="comment">drwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span><span class="string">.</span> <span class="comment">2</span> <span class="comment">8980</span> <span class="comment">users</span>  <span class="comment">4096</span> <span class="comment">9月</span>  <span class="comment">21</span> <span class="comment">22:14</span> <span class="comment">php_client</span>
<span class="literal">-</span><span class="comment">rw</span><span class="literal">-</span><span class="comment">r</span><span class="literal">-</span><span class="literal">-</span><span class="comment">r</span><span class="literal">-</span><span class="literal">-</span><span class="string">.</span> <span class="comment">1</span> <span class="comment">8980</span> <span class="comment">users</span>  <span class="comment">2380</span> <span class="comment">9月</span>  <span class="comment">21</span> <span class="comment">22:14</span> <span class="comment">README</span><span class="string">.</span><span class="comment">md</span>
<span class="literal">-</span><span class="comment">rwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span><span class="string">.</span> <span class="comment">1</span> <span class="comment">8980</span> <span class="comment">users</span>  <span class="comment">1768</span> <span class="comment">9月</span>  <span class="comment">21</span> <span class="comment">22:14</span> <span class="comment">restart</span><span class="string">.</span><span class="comment">sh</span>
<span class="literal">-</span><span class="comment">rwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span><span class="string">.</span> <span class="comment">1</span> <span class="comment">8980</span> <span class="comment">users</span>  <span class="comment">1680</span> <span class="comment">9月</span>  <span class="comment">21</span> <span class="comment">22:14</span> <span class="comment">stop</span><span class="string">.</span><span class="comment">sh</span>
<span class="comment">drwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span><span class="string">.</span> <span class="comment">4</span> <span class="comment">8980</span> <span class="comment">users</span>  <span class="comment">4096</span> <span class="comment">9月</span>  <span class="comment">21</span> <span class="comment">22:14</span> <span class="comment">storage</span>
<span class="comment">drwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span><span class="string">.</span> <span class="comment">2</span> <span class="comment">8980</span> <span class="comment">users</span>  <span class="comment">4096</span> <span class="comment">9月</span>  <span class="comment">21</span> <span class="comment">22:14</span> <span class="comment">test</span>
<span class="comment">drwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span><span class="string">.</span> <span class="comment">2</span> <span class="comment">8980</span> <span class="comment">users</span>  <span class="comment">4096</span> <span class="comment">9月</span>  <span class="comment">21</span> <span class="comment">22:14</span> <span class="comment">tracker</span>
<span class="title">[</span><span class="comment">root@tracker</span> <span class="comment">FastDFS</span><span class="title">]</span><span class="comment">#</span> <span class="string">.</span><span class="comment">/make</span><span class="string">.</span><span class="comment">sh</span> 
</code></pre>

<p>执行make.sh 遇到的错误</p>

<pre><code class="avrasm">
[root@tracker FastDFS]<span class="preprocessor"># ./make.sh </span>
cc -Wall -D_FILE_OFFSET_BITS=<span class="number">64</span> -D_GNU_SOURCE -g -O -DDEBUG_FLAG -DOS_LINUX -DIOEVENT_USE_EPOLL -c -o ../common/fdfs_global<span class="preprocessor">.o</span> ../common/fdfs_global<span class="preprocessor">.c</span>  -I../common -I/usr/include/fastcommon
../common/fdfs_global<span class="preprocessor">.c</span>:<span class="number">20</span>:<span class="number">20</span>: 错误：logger<span class="preprocessor">.h</span>：没有那个文件或目录
在包含自 ../common/fdfs_global<span class="preprocessor">.c</span>：<span class="number">21</span> 的文件中:
../common/fdfs_global<span class="preprocessor">.h</span>:<span class="number">14</span>:<span class="number">27</span>: 错误：common_define<span class="preprocessor">.h</span>：没有那个文件或目录
../common/fdfs_global<span class="preprocessor">.h</span>:<span class="number">16</span>:<span class="number">29</span>: 错误：connection_pool<span class="preprocessor">.h</span>：没有那个文件或目录
<span class="keyword">In</span> file included from ../common/fdfs_global<span class="preprocessor">.c</span>:<span class="number">21</span>:
../common/fdfs_global<span class="preprocessor">.h</span>:<span class="number">26</span>: 错误：‘MAX_PATH_SIZE’未声明(不在函数内)
../common/fdfs_global<span class="preprocessor">.h</span>:<span class="number">27</span>: 错误：expected ‘=’, ‘,’, ‘<span class="comment">;’, ‘asm’ or ‘__attribute__’ before ‘g_fdfs_version’</span>
../common/fdfs_global<span class="preprocessor">.h</span>:<span class="number">28</span>: 错误：expected ‘=’, ‘,’, ‘<span class="comment">;’, ‘asm’ or ‘__attribute__’ before ‘g_use_connection_pool’</span>
../common/fdfs_global<span class="preprocessor">.h</span>:<span class="number">29</span>: 错误：expected ‘=’, ‘,’, ‘<span class="comment">;’, ‘asm’ or ‘__attribute__’ before ‘g_connection_pool’</span>
../common/fdfs_global<span class="preprocessor">.c</span>:<span class="number">23</span>: 错误：‘DEFAULT_CONNECT_TIMEOUT’未声明(不在函数内)
../common/fdfs_global<span class="preprocessor">.c</span>:<span class="number">24</span>: 错误：‘DEFAULT_NETWORK_TIMEOUT’未声明(不在函数内)
../common/fdfs_global<span class="preprocessor">.c</span>:<span class="number">26</span>: 错误：expected ‘=’, ‘,’, ‘<span class="comment">;’, ‘asm’ or ‘__attribute__’ before ‘g_fdfs_version’</span>
../common/fdfs_global<span class="preprocessor">.c</span>:<span class="number">27</span>: 错误：expected ‘=’, ‘,’, ‘<span class="comment">;’, ‘asm’ or ‘__attribute__’ before ‘g_use_connection_pool’</span>
../common/fdfs_global<span class="preprocessor">.c</span>:<span class="number">28</span>: 错误：expected ‘=’, ‘,’, ‘<span class="comment">;’, ‘asm’ or ‘__attribute__’ before ‘g_connection_pool’</span>
../common/fdfs_global<span class="preprocessor">.c</span>: 在函数‘fdfs_check_data_filename’中:
../common/fdfs_global<span class="preprocessor">.c</span>:<span class="number">39</span>: 警告：隐式声明函数‘logError’
../common/fdfs_global<span class="preprocessor">.c</span>:<span class="number">45</span>: 警告：隐式声明函数‘IS_UPPER_HEX’
<span class="label">make:</span> *** [../common/fdfs_global<span class="preprocessor">.o</span>] 错误 <span class="number">1</span>
cc -Wall -D_FILE_OFFSET_BITS=<span class="number">64</span> -D_GNU_SOURCE -g -O -DDEBUG_FLAG -DOS_LINUX -DIOEVENT_USE_EPOLL -c -o ../common/fdfs_global<span class="preprocessor">.o</span> ../common/fdfs_global<span class="preprocessor">.c</span>  -I. -Itrunk_mgr -I../common -I../tracker -I../client -Ifdht_client -I/usr/include/fastcommon
../common/fdfs_global<span class="preprocessor">.c</span>:<span class="number">20</span>:<span class="number">20</span>: 错误：logger<span class="preprocessor">.h</span>：没有那个文件或目录
在包含自 ../common/fdfs_global<span class="preprocessor">.c</span>：<span class="number">21</span> 的文件中:
../common/fdfs_global<span class="preprocessor">.h</span>:<span class="number">14</span>:<span class="number">27</span>: 错误：common_define<span class="preprocessor">.h</span>：没有那个文件或目录
../common/fdfs_global<span class="preprocessor">.h</span>:<span class="number">16</span>:<span class="number">29</span>: 错误：connection_pool<span class="preprocessor">.h</span>：没有那个文件或目录
<span class="keyword">In</span> file included from ../common/fdfs_global<span class="preprocessor">.c</span>:<span class="number">21</span>:
../common/fdfs_global<span class="preprocessor">.h</span>:<span class="number">26</span>: 错误：‘MAX_PATH_SIZE’未声明(不在函数内)
../common/fdfs_global<span class="preprocessor">.h</span>:<span class="number">27</span>: 错误：expected ‘=’, ‘,’, ‘<span class="comment">;’, ‘asm’ or ‘__attribute__’ before ‘g_fdfs_version’</span>
../common/fdfs_global<span class="preprocessor">.h</span>:<span class="number">28</span>: 错误：expected ‘=’, ‘,’, ‘<span class="comment">;’, ‘asm’ or ‘__attribute__’ before ‘g_use_connection_pool’</span>
../common/fdfs_global<span class="preprocessor">.h</span>:<span class="number">29</span>: 错误：expected ‘=’, ‘,’, ‘<span class="comment">;’, ‘asm’ or ‘__attribute__’ before ‘g_connection_pool’</span>
../common/fdfs_global<span class="preprocessor">.c</span>:<span class="number">23</span>: 错误：‘DEFAULT_CONNECT_TIMEOUT’未声明(不在函数内)
../common/fdfs_global<span class="preprocessor">.c</span>:<span class="number">24</span>: 错误：‘DEFAULT_NETWORK_TIMEOUT’未声明(不在函数内)
../common/fdfs_global<span class="preprocessor">.c</span>:<span class="number">26</span>: 错误：expected ‘=’, ‘,’, ‘<span class="comment">;’, ‘asm’ or ‘__attribute__’ before ‘g_fdfs_version’</span>
../common/fdfs_global<span class="preprocessor">.c</span>:<span class="number">27</span>: 错误：expected ‘=’, ‘,’, ‘<span class="comment">;’, ‘asm’ or ‘__attribute__’ before ‘g_use_connection_pool’</span>
../common/fdfs_global<span class="preprocessor">.c</span>:<span class="number">28</span>: 错误：expected ‘=’, ‘,’, ‘<span class="comment">;’, ‘asm’ or ‘__attribute__’ before ‘g_connection_pool’</span>
../common/fdfs_global<span class="preprocessor">.c</span>: 在函数‘fdfs_check_data_filename’中:
../common/fdfs_global<span class="preprocessor">.c</span>:<span class="number">39</span>: 警告：隐式声明函数‘logError’
../common/fdfs_global<span class="preprocessor">.c</span>:<span class="number">45</span>: 警告：隐式声明函数‘IS_UPPER_HEX’
<span class="label">make:</span> *** [../common/fdfs_global<span class="preprocessor">.o</span>] 错误 <span class="number">1</span>
cc -Wall -D_FILE_OFFSET_BITS=<span class="number">64</span> -D_GNU_SOURCE -g -O -DDEBUG_FLAG -DOS_LINUX -DIOEVENT_USE_EPOLL -c -o ../common/fdfs_global<span class="preprocessor">.o</span> ../common/fdfs_global<span class="preprocessor">.c</span>  -I../common -I../tracker -I/usr/include/fastcommon
../common/fdfs_global<span class="preprocessor">.c</span>:<span class="number">20</span>:<span class="number">20</span>: 错误：logger<span class="preprocessor">.h</span>：没有那个文件或目录
在包含自 ../common/fdfs_global<span class="preprocessor">.c</span>：<span class="number">21</span> 的文件中:
../common/fdfs_global<span class="preprocessor">.h</span>:<span class="number">14</span>:<span class="number">27</span>: 错误：common_define<span class="preprocessor">.h</span>：没有那个文件或目录
../common/fdfs_global<span class="preprocessor">.h</span>:<span class="number">16</span>:<span class="number">29</span>: 错误：connection_pool<span class="preprocessor">.h</span>：没有那个文件或目录
<span class="keyword">In</span> file included from ../common/fdfs_global<span class="preprocessor">.c</span>:<span class="number">21</span>:
../common/fdfs_global<span class="preprocessor">.h</span>:<span class="number">26</span>: 错误：‘MAX_PATH_SIZE’未声明(不在函数内)
../common/fdfs_global<span class="preprocessor">.h</span>:<span class="number">27</span>: 错误：expected ‘=’, ‘,’, ‘<span class="comment">;’, ‘asm’ or ‘__attribute__’ before ‘g_fdfs_version’</span>
../common/fdfs_global<span class="preprocessor">.h</span>:<span class="number">28</span>: 错误：expected ‘=’, ‘,’, ‘<span class="comment">;’, ‘asm’ or ‘__attribute__’ before ‘g_use_connection_pool’</span>
../common/fdfs_global<span class="preprocessor">.h</span>:<span class="number">29</span>: 错误：expected ‘=’, ‘,’, ‘<span class="comment">;’, ‘asm’ or ‘__attribute__’ before ‘g_connection_pool’</span>
../common/fdfs_global<span class="preprocessor">.c</span>:<span class="number">23</span>: 错误：‘DEFAULT_CONNECT_TIMEOUT’未声明(不在函数内)
../common/fdfs_global<span class="preprocessor">.c</span>:<span class="number">24</span>: 错误：‘DEFAULT_NETWORK_TIMEOUT’未声明(不在函数内)
../common/fdfs_global<span class="preprocessor">.c</span>:<span class="number">26</span>: 错误：expected ‘=’, ‘,’, ‘<span class="comment">;’, ‘asm’ or ‘__attribute__’ before ‘g_fdfs_version’</span>
../common/fdfs_global<span class="preprocessor">.c</span>:<span class="number">27</span>: 错误：expected ‘=’, ‘,’, ‘<span class="comment">;’, ‘asm’ or ‘__attribute__’ before ‘g_use_connection_pool’</span>
../common/fdfs_global<span class="preprocessor">.c</span>:<span class="number">28</span>: 错误：expected ‘=’, ‘,’, ‘<span class="comment">;’, ‘asm’ or ‘__attribute__’ before ‘g_connection_pool’</span>
../common/fdfs_global<span class="preprocessor">.c</span>: 在函数‘fdfs_check_data_filename’中:
../common/fdfs_global<span class="preprocessor">.c</span>:<span class="number">39</span>: 警告：隐式声明函数‘logError’
../common/fdfs_global<span class="preprocessor">.c</span>:<span class="number">45</span>: 警告：隐式声明函数‘IS_UPPER_HEX’
<span class="label">make:</span> *** [../common/fdfs_global<span class="preprocessor">.o</span>] 错误 <span class="number">1</span>
</code></pre>

<p>看 源码目录下的INSTALL文件发现，需要安装 libfastcommon</p>

<pre><code class="actionscript">
#step <span class="number">1.</span> download libfastcommon source <span class="package"><span class="keyword">package</span> <span class="title">from</span> <span class="title">github</span> <span class="title">and</span> <span class="title">install</span> <span class="title">it</span>,
   <span class="title">the</span> <span class="title">github</span> <span class="title">address</span>:
   <span class="title">https</span>://<span class="title">github</span>.<span class="title">com</span>/<span class="title">happyfish100</span>/<span class="title">libfastcommon</span>.<span class="title">git</span>
</span></code></pre>

<p>到如上的网址下载 libfastcommon进行安装，上传至服务器的src目录下</p>

<pre><code class="avrasm">
[root@tracker src]<span class="preprocessor"># unzip libfastcommon-master.zip </span>
[root@tracker src]<span class="preprocessor"># cd libfastcommon-master</span>
[root@tracker libfastcommon-master]<span class="preprocessor"># ls</span>
HISTORY  INSTALL  libfastcommon<span class="preprocessor">.spec</span>  make<span class="preprocessor">.sh</span>  README  src
[root@tracker libfastcommon-master]<span class="preprocessor"># ./make.sh </span>
[root@tracker libfastcommon-master]<span class="preprocessor"># ./make.sh install</span>
mkdir -p /usr/lib64
install -m <span class="number">755</span> libfastcommon<span class="preprocessor">.so</span> /usr/lib64
mkdir -p /usr/include/fastcommon
install -m <span class="number">644</span> common_define<span class="preprocessor">.h</span> hash<span class="preprocessor">.h</span> chain<span class="preprocessor">.h</span> logger<span class="preprocessor">.h</span> base64<span class="preprocessor">.h</span> shared_func<span class="preprocessor">.h</span> pthread_func<span class="preprocessor">.h</span> ini_file_reader<span class="preprocessor">.h</span> _os_bits<span class="preprocessor">.h</span> sockopt<span class="preprocessor">.h</span> sched_thread<span class="preprocessor">.h</span> http_func<span class="preprocessor">.h</span> md5<span class="preprocessor">.h</span> local_ip_func<span class="preprocessor">.h</span> avl_tree<span class="preprocessor">.h</span> ioevent<span class="preprocessor">.h</span> ioevent_loop<span class="preprocessor">.h</span> fast_task_queue<span class="preprocessor">.h</span> fast_timer<span class="preprocessor">.h</span> process_ctrl<span class="preprocessor">.h</span> fast_mblock<span class="preprocessor">.h</span> connection_pool<span class="preprocessor">.h</span> /usr/include/fastcommon
</code></pre>

<p>至此libfastcommon安装完成。</p>

<p>再回到 FastDFS目录下来安装FastDFS</p>

<pre><code class="brainfuck">
<span class="title">[</span><span class="comment">root@tracker</span> <span class="comment">libfastcommon</span><span class="literal">-</span><span class="comment">master</span><span class="title">]</span><span class="comment">#</span> <span class="comment">cd</span> <span class="string">.</span><span class="string">.</span><span class="comment">/FastDFS</span>
<span class="title">[</span><span class="comment">root@tracker</span> <span class="comment">FastDFS</span><span class="title">]</span><span class="comment">#</span> <span class="string">.</span><span class="comment">/make</span><span class="string">.</span><span class="comment">sh</span> 
<span class="comment">cc</span> <span class="literal">-</span><span class="comment">Wall</span> <span class="literal">-</span><span class="comment">D_FILE_OFFSET_BITS=64</span> <span class="literal">-</span><span class="comment">D_GNU_SOURCE</span> <span class="literal">-</span><span class="comment">g</span> <span class="literal">-</span><span class="comment">O</span> <span class="literal">-</span><span class="comment">DDEBUG_FLAG</span> <span class="literal">-</span><span class="comment">DOS_LINUX</span> <span class="literal">-</span><span class="comment">DIOEVENT_USE_EPOLL</span> <span class="literal">-</span><span class="comment">c</span> <span class="literal">-</span><span class="comment">o</span> <span class="string">.</span><span class="string">.</span><span class="comment">/common/fdfs_global</span><span class="string">.</span><span class="comment">o</span> <span class="string">.</span><span class="string">.</span><span class="comment">/common/fdfs_global</span><span class="string">.</span><span class="comment">c</span>  <span class="literal">-</span><span class="comment">I</span><span class="string">.</span><span class="string">.</span><span class="comment">/common</span> <span class="literal">-</span><span class="comment">I/usr/include/fastcommon</span>
<span class="comment">cc</span> <span class="literal">-</span><span class="comment">Wall</span> <span class="literal">-</span><span class="comment">D_FILE_OFFSET_BITS=64</span> <span class="literal">-</span><span class="comment">D_GNU_SOURCE</span> <span class="literal">-</span><span class="comment">g</span> <span class="literal">-</span><span class="comment">O</span> <span class="literal">-</span><span class="comment">DDEBUG_FLAG</span> <span class="literal">-</span><span class="comment">DOS_LINUX</span> <span class="literal">-</span><span class="comment">DIOEVENT_USE_EPOLL</span> <span class="literal">-</span><span class="comment">c</span> <span class="literal">-</span><span class="comment">o</span> <span class="comment">tracker_proto</span><span class="string">.</span><span class="comment">o</span> <span class="comment">tracker_proto</span><span class="string">.</span><span class="comment">c</span>  <span class="literal">-</span><span class="comment">I</span><span class="string">.</span><span class="string">.</span><span class="comment">/common</span> <span class="literal">-</span><span class="comment">I/usr/include/fastcommon</span>
<span class="comment">cc</span> <span class="literal">-</span><span class="comment">Wall</span> <span class="literal">-</span><span class="comment">D_FILE_OFFSET_BITS=64</span> <span class="literal">-</span><span class="comment">D_GNU_SOURCE</span> <span class="literal">-</span><span class="comment">g</span> <span class="literal">-</span><span class="comment">O</span> <span class="literal">-</span><span class="comment">DDEBUG_FLAG</span> <span class="literal">-</span><span class="comment">DOS_LINUX</span> <span class="literal">-</span><span class="comment">DIOEVENT_USE_EPOLL</span> <span class="literal">-</span><span class="comment">c</span> <span class="literal">-</span><span class="comment">o</span> <span class="comment">tracker_mem</span><span class="string">.</span><span class="comment">o</span> <span class="comment">tracker_mem</span><span class="string">.</span><span class="comment">c</span>  <span class="literal">-</span><span class="comment">I</span><span class="string">.</span><span class="string">.</span><span class="comment">/common</span> <span class="literal">-</span><span class="comment">I/usr/include/fastcommon</span>
<span class="comment">cc</span> <span class="literal">-</span><span class="comment">Wall</span> <span class="literal">-</span><span class="comment">D_FILE_OFFSET_BITS=64</span> <span class="literal">-</span><span class="comment">D_GNU_SOURCE</span> <span class="literal">-</span><span class="comment">g</span> <span class="literal">-</span><span class="comment">O</span> <span class="literal">-</span><span class="comment">DDEBUG_FLAG</span> <span class="literal">-</span><span class="comment">DOS_LINUX</span> <span class="literal">-</span><span class="comment">DIOEVENT_USE_EPOLL</span> <span class="literal">-</span><span class="comment">c</span> <span class="literal">-</span><span class="comment">o</span> <span class="comment">tracker_service</span><span class="string">.</span><span class="comment">o</span> <span class="comment">tracker_service</span><span class="string">.</span><span class="comment">c</span>  <span class="literal">-</span><span class="comment">I</span><span class="string">.</span><span class="string">.</span><span class="comment">/common</span> <span class="literal">-</span><span class="comment">I/usr/include/fastcommon</span>
<span class="comment">cc</span> <span class="literal">-</span><span class="comment">Wall</span> <span class="literal">-</span><span class="comment">D_FILE_OFFSET_BITS=64</span> <span class="literal">-</span><span class="comment">D_GNU_SOURCE</span> <span class="literal">-</span><span class="comment">g</span> <span class="literal">-</span><span class="comment">O</span> <span class="literal">-</span><span class="comment">DDEBUG_FLAG</span> <span class="literal">-</span><span class="comment">DOS_LINUX</span> <span class="literal">-</span><span class="comment">DIOEVENT_USE_EPOLL</span> <span class="literal">-</span><span class="comment">c</span> <span class="literal">-</span><span class="comment">o</span> <span class="comment">tracker_status</span><span class="string">.</span><span class="comment">o</span> <span class="comment">tracker_status</span><span class="string">.</span><span class="comment">c</span>  <span class="literal">-</span><span class="comment">I</span><span class="string">.</span><span class="string">.</span><span class="comment">/common</span> <span class="literal">-</span><span class="comment">I/usr/include/fastcommon</span>
<span class="comment">cc</span> <span class="literal">-</span><span class="comment">Wall</span> <span class="literal">-</span><span class="comment">D_FILE_OFFSET_BITS=64</span> <span class="literal">-</span><span class="comment">D_GNU_SOURCE</span> <span class="literal">-</span><span class="comment">g</span> <span class="literal">-</span><span class="comment">O</span> <span class="literal">-</span><span class="comment">DDEBUG_FLAG</span> <span class="literal">-</span><span class="comment">DOS_LINUX</span> <span class="literal">-</span><span class="comment">DIOEVENT_USE_EPOLL</span> <span class="literal">-</span><span class="comment">c</span> <span class="literal">-</span><span class="comment">o</span> <span class="comment">tracker_global</span><span class="string">.</span><span class="comment">o</span> <span class="comment">tracker_global</span><span class="string">.</span><span class="comment">c</span>  <span class="literal">-</span><span class="comment">I</span><span class="string">.</span><span class="string">.</span><span class="comment">/common</span> <span class="literal">-</span><span class="comment">I/usr/include/fastcommon</span>
<span class="comment">cc</span> <span class="literal">-</span><span class="comment">Wall</span> <span class="literal">-</span><span class="comment">D_FILE_OFFSET_BITS=64</span> <span class="literal">-</span><span class="comment">D_GNU_SOURCE</span> <span class="literal">-</span><span class="comment">g</span> <span class="literal">-</span><span class="comment">O</span> <span class="literal">-</span><span class="comment">DDEBUG_FLAG</span> <span class="literal">-</span><span class="comment">DOS_LINUX</span> <span class="literal">-</span><span class="comment">DIOEVENT_USE_EPOLL</span> <span class="literal">-</span><span class="comment">c</span> <span class="literal">-</span><span class="comment">o</span> <span class="comment">tracker_func</span><span class="string">.</span><span class="comment">o</span> <span class="comment">tracker_func</span><span class="string">.</span><span class="comment">c</span>  <span class="literal">-</span><span class="comment">I</span><span class="string">.</span><span class="string">.</span><span class="comment">/common</span> <span class="literal">-</span><span class="comment">I/usr/include/fastcommon</span>
<span class="comment">cc</span> <span class="literal">-</span><span class="comment">Wall</span> <span class="literal">-</span><span class="comment">D_FILE_OFFSET_BITS=64</span> <span class="literal">-</span><span class="comment">D_GNU_SOURCE</span> <span class="literal">-</span><span class="comment">g</span> <span class="literal">-</span><span class="comment">O</span> <span class="literal">-</span><span class="comment">DDEBUG_FLAG</span> <span class="literal">-</span><span class="comment">DOS_LINUX</span> <span class="literal">-</span><span class="comment">DIOEVENT_USE_EPOLL</span> <span class="literal">-</span><span class="comment">c</span> <span class="literal">-</span><span class="comment">o</span> <span class="comment">fdfs_shared_func</span><span class="string">.</span><span class="comment">o</span> <span class="comment">fdfs_shared_func</span><span class="string">.</span><span class="comment">c</span>  <span class="literal">-</span><span class="comment">I</span><span class="string">.</span><span class="string">.</span><span class="comment">/common</span> <span class="literal">-</span><span class="comment">I/usr/include/fastcommon</span>
<span class="comment">cc</span> <span class="literal">-</span><span class="comment">Wall</span> <span class="literal">-</span><span class="comment">D_FILE_OFFSET_BITS=64</span> <span class="literal">-</span><span class="comment">D_GNU_SOURCE</span> <span class="literal">-</span><span class="comment">g</span> <span class="literal">-</span><span class="comment">O</span> <span class="literal">-</span><span class="comment">DDEBUG_FLAG</span> <span class="literal">-</span><span class="comment">DOS_LINUX</span> <span class="literal">-</span><span class="comment">DIOEVENT_USE_EPOLL</span> <span class="literal">-</span><span class="comment">c</span> <span class="literal">-</span><span class="comment">o</span> <span class="comment">tracker_nio</span><span class="string">.</span><span class="comment">o</span> <span class="comment">tracker_nio</span><span class="string">.</span><span class="comment">c</span>  <span class="literal">-</span><span class="comment">I</span><span class="string">.</span><span class="string">.</span><span class="comment">/common</span> <span class="literal">-</span><span class="comment">I/usr/include/fastcommon</span>
<span class="comment">cc</span> <span class="literal">-</span><span class="comment">Wall</span> <span class="literal">-</span><span class="comment">D_FILE_OFFSET_BITS=64</span> <span class="literal">-</span><span class="comment">D_GNU_SOURCE</span> <span class="literal">-</span><span class="comment">g</span> <span class="literal">-</span><span class="comment">O</span> <span class="literal">-</span><span class="comment">DDEBUG_FLAG</span> <span class="literal">-</span><span class="comment">DOS_LINUX</span> <span class="literal">-</span><span class="comment">DIOEVENT_USE_EPOLL</span> <span class="literal">-</span><span class="comment">c</span> <span class="literal">-</span><span class="comment">o</span> <span class="comment">tracker_relationship</span><span class="string">.</span><span class="comment">o</span> <span class="comment">tracker_relationship</span><span class="string">.</span><span class="comment">c</span>  <span class="literal">-</span><span class="comment">I</span><span class="string">.</span><span class="string">.</span><span class="comment">/common</span> <span class="literal">-</span><span class="comment">I/usr/include/fastcommon</span>
<span class="comment">cc</span> <span class="literal">-</span><span class="comment">Wall</span> <span class="literal">-</span><span class="comment">D_FILE_OFFSET_BITS=64</span> <span class="literal">-</span><span class="comment">D_GNU_SOURCE</span> <span class="literal">-</span><span class="comment">g</span> <span class="literal">-</span><span class="comment">O</span> <span class="literal">-</span><span class="comment">DDEBUG_FLAG</span> <span class="literal">-</span><span class="comment">DOS_LINUX</span> <span class="literal">-</span><span class="comment">DIOEVENT_USE_EPOLL</span> <span class="literal">-</span><span class="comment">c</span> <span class="literal">-</span><span class="comment">o</span> <span class="comment">tracker_dump</span><span class="string">.</span><span class="comment">o</span> <span class="comment">tracker_dump</span><span class="string">.</span><span class="comment">c</span>  <span class="literal">-</span><span class="comment">I</span><span class="string">.</span><span class="string">.</span><span class="comment">/common</span> <span class="literal">-</span><span class="comment">I/usr/include/fastcommon</span>
<span class="comment">cc</span> <span class="literal">-</span><span class="comment">Wall</span> <span class="literal">-</span><span class="comment">D_FILE_OFFSET_BITS=64</span> <span class="literal">-</span><span class="comment">D_GNU_SOURCE</span> <span class="literal">-</span><span class="comment">g</span> <span class="literal">-</span><span class="comment">O</span> <span class="literal">-</span><span class="comment">DDEBUG_FLAG</span> <span class="literal">-</span><span class="comment">DOS_LINUX</span> <span class="literal">-</span><span class="comment">DIOEVENT_USE_EPOLL</span> <span class="literal">-</span><span class="comment">c</span> <span class="literal">-</span><span class="comment">o</span> <span class="string">.</span><span class="string">.</span><span class="comment">/common/linux_stack_trace</span><span class="string">.</span><span class="comment">o</span> <span class="string">.</span><span class="string">.</span><span class="comment">/common/linux_stack_trace</span><span class="string">.</span><span class="comment">c</span>  <span class="literal">-</span><span class="comment">I</span><span class="string">.</span><span class="string">.</span><span class="comment">/common</span> <span class="literal">-</span><span class="comment">I/usr/include/fastcommon</span>
<span class="comment">cc</span> <span class="literal">-</span><span class="comment">Wall</span> <span class="literal">-</span><span class="comment">D_FILE_OFFSET_BITS=64</span> <span class="literal">-</span><span class="comment">D_GNU_SOURCE</span> <span class="literal">-</span><span class="comment">g</span> <span class="literal">-</span><span class="comment">O</span> <span class="literal">-</span><span class="comment">DDEBUG_FLAG</span> <span class="literal">-</span><span class="comment">DOS_LINUX</span> <span class="literal">-</span><span class="comment">DIOEVENT_USE_EPOLL</span> <span class="literal">-</span><span class="comment">o</span> <span class="comment">fdfs_trackerd</span> <span class="comment">fdfs_trackerd</span><span class="string">.</span><span class="comment">c</span>  <span class="string">.</span><span class="string">.</span><span class="comment">/common/fdfs_global</span><span class="string">.</span><span class="comment">o</span> <span class="comment">tracker_proto</span><span class="string">.</span><span class="comment">o</span> <span class="comment">tracker_mem</span><span class="string">.</span><span class="comment">o</span> <span class="comment">tracker_service</span><span class="string">.</span><span class="comment">o</span> <span class="comment">tracker_status</span><span class="string">.</span><span class="comment">o</span> <span class="comment">tracker_global</span><span class="string">.</span><span class="comment">o</span> <span class="comment">tracker_func</span><span class="string">.</span><span class="comment">o</span> <span class="comment">fdfs_shared_func</span><span class="string">.</span><span class="comment">o</span> <span class="comment">tracker_nio</span><span class="string">.</span><span class="comment">o</span> <span class="comment">tracker_relationship</span><span class="string">.</span><span class="comment">o</span> <span class="comment">tracker_dump</span><span class="string">.</span><span class="comment">o</span> <span class="string">.</span><span class="string">.</span><span class="comment">/common/linux_stack_trace</span><span class="string">.</span><span class="comment">o</span> <span class="literal">-</span><span class="comment">L/usr/local/lib</span>  <span class="literal">-</span><span class="comment">lpthread</span> <span class="literal">-</span><span class="comment">ldl</span> <span class="literal">-</span><span class="comment">rdynamic</span> <span class="literal">-</span><span class="comment">lfastcommon</span> <span class="literal">-</span><span class="comment">I</span><span class="string">.</span><span class="string">.</span><span class="comment">/common</span> <span class="literal">-</span><span class="comment">I/usr/include/fastcommon</span>
<span class="comment">cc</span> <span class="literal">-</span><span class="comment">Wall</span> <span class="literal">-</span><span class="comment">D_FILE_OFFSET_BITS=64</span> <span class="literal">-</span><span class="comment">D_GNU_SOURCE</span> <span class="literal">-</span><span class="comment">g</span> <span class="literal">-</span><span class="comment">O</span> <span class="literal">-</span><span class="comment">DDEBUG_FLAG</span> <span class="literal">-</span><span class="comment">DOS_LINUX</span> <span class="literal">-</span><span class="comment">DIOEVENT_USE_EPOLL</span> <span class="literal">-</span><span class="comment">c</span> <span class="literal">-</span><span class="comment">o</span> <span class="comment">tracker_client_thread</span><span class="string">.</span><span class="comment">o</span> <span class="comment">tracker_client_thread</span><span class="string">.</span><span class="comment">c</span>  <span class="literal">-</span><span class="comment">I</span><span class="string">.</span> <span class="literal">-</span><span class="comment">Itrunk_mgr</span> <span class="literal">-</span><span class="comment">I</span><span class="string">.</span><span class="string">.</span><span class="comment">/common</span> <span class="literal">-</span><span class="comment">I</span><span class="string">.</span><span class="string">.</span><span class="comment">/tracker</span> <span class="literal">-</span><span class="comment">I</span><span class="string">.</span><span class="string">.</span><span class="comment">/client</span> <span class="literal">-</span><span class="comment">Ifdht_client</span> <span class="literal">-</span><span class="comment">I/usr/include/fastcommon</span>
<span class="comment">cc</span> <span class="literal">-</span><span class="comment">Wall</span> <span class="literal">-</span><span class="comment">D_FILE_OFFSET_BITS=64</span> <span class="literal">-</span><span class="comment">D_GNU_SOURCE</span> <span class="literal">-</span><span class="comment">g</span> <span class="literal">-</span><span class="comment">O</span> <span class="literal">-</span><span class="comment">DDEBUG_FLAG</span> <span class="literal">-</span><span class="comment">DOS_LINUX</span> <span class="literal">-</span><span class="comment">DIOEVENT_USE_EPOLL</span> <span class="literal">-</span><span class="comment">c</span> <span class="literal">-</span><span class="comment">o</span> <span class="comment">storage_global</span><span class="string">.</span><span class="comment">o</span> <span class="comment">storage_global</span><span class="string">.</span><span class="comment">c</span>  <span class="literal">-</span><span class="comment">I</span><span class="string">.</span> <span class="literal">-</span><span class="comment">Itrunk_mgr</span> <span class="literal">-</span><span class="comment">I</span><span class="string">.</span><span class="string">.</span><span class="comment">/common</span> <span class="literal">-</span><span class="comment">I</span><span class="string">.</span><span class="string">.</span><span class="comment">/tracker</span> <span class="literal">-</span><span class="comment">I</span><span class="string">.</span><span class="string">.</span><span class="comment">/client</span> <span class="literal">-</span><span class="comment">Ifdht_client</span> <span class="literal">-</span><span class="comment">I/usr/include/fastcommon</span>
<span class="comment">cc</span> <span class="literal">-</span><span class="comment">Wall</span> <span class="literal">-</span><span class="comment">D_FILE_OFFSET_BITS=64</span> <span class="literal">-</span><span class="comment">D_GNU_SOURCE</span> <span class="literal">-</span><span class="comment">g</span> <span class="literal">-</span><span class="comment">O</span> <span class="literal">-</span><span class="comment">DDEBUG_FLAG</span> <span class="literal">-</span><span class="comment">DOS_LINUX</span> <span class="literal">-</span><span class="comment">DIOEVENT_USE_EPOLL</span> <span class="literal">-</span><span class="comment">c</span> <span class="literal">-</span><span class="comment">o</span> <span class="comment">storage_func</span><span class="string">.</span><span class="comment">o</span> <span class="comment">storage_func</span><span class="string">.</span><span class="comment">c</span>  <span class="literal">-</span><span class="comment">I</span><span class="string">.</span> <span class="literal">-</span><span class="comment">Itrunk_mgr</span> <span class="literal">-</span><span class="comment">I</span><span class="string">.</span><span class="string">.</span><span class="comment">/common</span> <span class="literal">-</span><span class="comment">I</span><span class="string">.</span><span class="string">.</span><span class="comment">/tracker</span> <span class="literal">-</span><span class="comment">I</span><span class="string">.</span><span class="string">.</span><span class="comment">/client</span> <span class="literal">-</span><span class="comment">Ifdht_client</span> <span class="literal">-</span><span class="comment">I/usr/include/fastcommon</span>
<span class="comment">cc</span> <span class="literal">-</span><span class="comment">Wall</span> <span class="literal">-</span><span class="comment">D_FILE_OFFSET_BITS=64</span> <span class="literal">-</span><span class="comment">D_GNU_SOURCE</span> <span class="literal">-</span><span class="comment">g</span> <span class="literal">-</span><span class="comment">O</span> <span class="literal">-</span><span class="comment">DDEBUG_FLAG</span> <span class="literal">-</span><span class="comment">DOS_LINUX</span> <span class="literal">-</span><span class="comment">DIOEVENT_USE_EPOLL</span> <span class="literal">-</span><span class="comment">c</span> <span class="literal">-</span><span class="comment">o</span> <span class="comment">storage_service</span><span class="string">.</span><span class="comment">o</span> <span class="comment">storage_service</span><span class="string">.</span><span class="comment">c</span>  <span class="literal">-</span><span class="comment">I</span><span class="string">.</span> <span class="literal">-</span><span class="comment">Itrunk_mgr</span> <span class="literal">-</span><span class="comment">I</span><span class="string">.</span><span class="string">.</span><span class="comment">/common</span> <span class="literal">-</span><span class="comment">I</span><span class="string">.</span><span class="string">.</span><span class="comment">/tracker</span> <span class="literal">-</span><span class="comment">I</span><span class="string">.</span><span class="string">.</span><span class="comment">/client</span> <span class="literal">-</span><span class="comment">Ifdht_client</span> <span class="literal">-</span><span class="comment">I/usr/include/fastcommon</span>
<span class="comment">cc</span> <span class="literal">-</span><span class="comment">Wall</span> <span class="literal">-</span><span class="comment">D_FILE_OFFSET_BITS=64</span> <span class="literal">-</span><span class="comment">D_GNU_SOURCE</span> <span class="literal">-</span><span class="comment">g</span> <span class="literal">-</span><span class="comment">O</span> <span class="literal">-</span><span class="comment">DDEBUG_FLAG</span> <span class="literal">-</span><span class="comment">DOS_LINUX</span> <span class="literal">-</span><span class="comment">DIOEVENT_USE_EPOLL</span> <span class="literal">-</span><span class="comment">c</span> <span class="literal">-</span><span class="comment">o</span> <span class="comment">storage_sync</span><span class="string">.</span><span class="comment">o</span> <span class="comment">storage_sync</span><span class="string">.</span><span class="comment">c</span>  <span class="literal">-</span><span class="comment">I</span><span class="string">.</span> <span class="literal">-</span><span class="comment">Itrunk_mgr</span> <span class="literal">-</span><span class="comment">I</span><span class="string">.</span><span class="string">.</span><span class="comment">/common</span> <span class="literal">-</span><span class="comment">I</span><span class="string">.</span><span class="string">.</span><span class="comment">/tracker</span> <span class="literal">-</span><span class="comment">I</span><span class="string">.</span><span class="string">.</span><span class="comment">/client</span> <span class="literal">-</span><span class="comment">Ifdht_client</span> <span class="literal">-</span><span class="comment">I/usr/include/fastcommon</span>
<span class="string">.</span><span class="string">.</span><span class="string">.</span>
<span class="title">[</span><span class="comment">root@tracker</span> <span class="comment">FastDFS</span><span class="title">]</span><span class="comment">#</span> <span class="string">.</span><span class="comment">/make</span><span class="string">.</span><span class="comment">sh</span> <span class="comment">install</span>
<span class="comment">mkdir</span> <span class="literal">-</span><span class="comment">p</span> <span class="comment">/usr/bin</span>
<span class="comment">mkdir</span> <span class="literal">-</span><span class="comment">p</span> <span class="comment">/etc/fdfs</span>
<span class="comment">cp</span> <span class="literal">-</span><span class="comment">f</span> <span class="comment">fdfs_trackerd</span> <span class="comment">/usr/bin</span>
<span class="comment">if</span> <span class="title">[</span> <span class="comment">!</span> <span class="literal">-</span><span class="comment">f</span> <span class="comment">/etc/fdfs/tracker</span><span class="string">.</span><span class="comment">conf</span><span class="string">.</span><span class="comment">sample</span> <span class="title">]</span><span class="comment">;</span> <span class="comment">then</span> <span class="comment">cp</span> <span class="literal">-</span><span class="comment">f</span> <span class="string">.</span><span class="string">.</span><span class="comment">/conf/tracker</span><span class="string">.</span><span class="comment">conf</span> <span class="comment">/etc/fdfs/tracker</span><span class="string">.</span><span class="comment">conf</span><span class="string">.</span><span class="comment">sample;</span> <span class="comment">fi</span>
<span class="comment">mkdir</span> <span class="literal">-</span><span class="comment">p</span> <span class="comment">/usr/bin</span>
<span class="comment">mkdir</span> <span class="literal">-</span><span class="comment">p</span> <span class="comment">/etc/fdfs</span>
<span class="comment">cp</span> <span class="literal">-</span><span class="comment">f</span> <span class="comment">fdfs_storaged</span>  <span class="comment">/usr/bin</span>
<span class="comment">if</span> <span class="title">[</span> <span class="comment">!</span> <span class="literal">-</span><span class="comment">f</span> <span class="comment">/etc/fdfs/storage</span><span class="string">.</span><span class="comment">conf</span><span class="string">.</span><span class="comment">sample</span> <span class="title">]</span><span class="comment">;</span> <span class="comment">then</span> <span class="comment">cp</span> <span class="literal">-</span><span class="comment">f</span> <span class="string">.</span><span class="string">.</span><span class="comment">/conf/storage</span><span class="string">.</span><span class="comment">conf</span> <span class="comment">/etc/fdfs/storage</span><span class="string">.</span><span class="comment">conf</span><span class="string">.</span><span class="comment">sample;</span> <span class="comment">fi</span>
<span class="comment">mkdir</span> <span class="literal">-</span><span class="comment">p</span> <span class="comment">/usr/bin</span>
<span class="comment">mkdir</span> <span class="literal">-</span><span class="comment">p</span> <span class="comment">/etc/fdfs</span>
<span class="comment">mkdir</span> <span class="literal">-</span><span class="comment">p</span> <span class="comment">/usr/lib64</span>
<span class="comment">cp</span> <span class="literal">-</span><span class="comment">f</span> <span class="comment">fdfs_monitor</span> <span class="comment">fdfs_test</span> <span class="comment">fdfs_test1</span> <span class="comment">fdfs_crc32</span> <span class="comment">fdfs_upload_file</span> <span class="comment">fdfs_download_file</span> <span class="comment">fdfs_delete_file</span> <span class="comment">fdfs_file_info</span> <span class="comment">fdfs_appender_test</span> <span class="comment">fdfs_appender_test1</span> <span class="comment">fdfs_append_file</span> <span class="comment">fdfs_upload_appender</span> <span class="comment">/usr/bin</span>
<span class="comment">if</span> <span class="title">[</span> <span class="comment">0</span> <span class="literal">-</span><span class="comment">eq</span> <span class="comment">1</span> <span class="title">]</span><span class="comment">;</span> <span class="comment">then</span> <span class="comment">cp</span> <span class="literal">-</span><span class="comment">f</span> <span class="comment">libfdfsclient</span><span class="string">.</span><span class="comment">a</span> <span class="comment">/usr/lib64;</span> <span class="comment">fi</span>
<span class="comment">if</span> <span class="title">[</span> <span class="comment">1</span> <span class="literal">-</span><span class="comment">eq</span> <span class="comment">1</span> <span class="title">]</span><span class="comment">;</span> <span class="comment">then</span> <span class="comment">cp</span> <span class="literal">-</span><span class="comment">f</span> <span class="comment">libfdfsclient</span><span class="string">.</span><span class="comment">so</span> <span class="comment">/usr/lib64;</span> <span class="comment">fi</span>
<span class="comment">mkdir</span> <span class="literal">-</span><span class="comment">p</span> <span class="comment">/usr/include/fastdfs</span>
<span class="comment">cp</span> <span class="literal">-</span><span class="comment">f</span> <span class="string">.</span><span class="string">.</span><span class="comment">/common/fdfs_define</span><span class="string">.</span><span class="comment">h</span> <span class="string">.</span><span class="string">.</span><span class="comment">/common/fdfs_global</span><span class="string">.</span><span class="comment">h</span> <span class="string">.</span><span class="string">.</span><span class="comment">/common/mime_file_parser</span><span class="string">.</span><span class="comment">h</span> <span class="string">.</span><span class="string">.</span><span class="comment">/common/fdfs_http_shared</span><span class="string">.</span><span class="comment">h</span> <span class="string">.</span><span class="string">.</span><span class="comment">/tracker/tracker_types</span><span class="string">.</span><span class="comment">h</span> <span class="string">.</span><span class="string">.</span><span class="comment">/tracker/tracker_proto</span><span class="string">.</span><span class="comment">h</span> <span class="string">.</span><span class="string">.</span><span class="comment">/tracker/fdfs_shared_func</span><span class="string">.</span><span class="comment">h</span> <span class="string">.</span><span class="string">.</span><span class="comment">/storage/trunk_mgr/trunk_shared</span><span class="string">.</span><span class="comment">h</span> <span class="comment">tracker_client</span><span class="string">.</span><span class="comment">h</span> <span class="comment">storage_client</span><span class="string">.</span><span class="comment">h</span> <span class="comment">storage_client1</span><span class="string">.</span><span class="comment">h</span> <span class="comment">client_func</span><span class="string">.</span><span class="comment">h</span> <span class="comment">client_global</span><span class="string">.</span><span class="comment">h</span> <span class="comment">fdfs_client</span><span class="string">.</span><span class="comment">h</span> <span class="comment">/usr/include/fastdfs</span>
<span class="comment">if</span> <span class="title">[</span> <span class="comment">!</span> <span class="literal">-</span><span class="comment">f</span> <span class="comment">/etc/fdfs/client</span><span class="string">.</span><span class="comment">conf</span><span class="string">.</span><span class="comment">sample</span> <span class="title">]</span><span class="comment">;</span> <span class="comment">then</span> <span class="comment">cp</span> <span class="literal">-</span><span class="comment">f</span> <span class="string">.</span><span class="string">.</span><span class="comment">/conf/client</span><span class="string">.</span><span class="comment">conf</span> <span class="comment">/etc/fdfs/client</span><span class="string">.</span><span class="comment">conf</span><span class="string">.</span><span class="comment">sample;</span> <span class="comment">fi</span>
</code></pre>

<p>至此FastDFS在 tracker上安装完成，所有的可执行文件位于 /usr/bin 目录下，以fdfs开头的文件</p>

<pre><code class="brainfuck">
<span class="title">[</span><span class="comment">root@tracker</span> <span class="comment">FastDFS</span><span class="title">]</span><span class="comment">#</span> <span class="comment">ll</span> <span class="comment">/usr/bin/fd*</span>
<span class="literal">-</span><span class="comment">rwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span><span class="string">.</span> <span class="comment">1</span> <span class="comment">root</span> <span class="comment">root</span> <span class="comment">257631</span> <span class="comment">10月</span> <span class="comment">28</span> <span class="comment">11:29</span> <span class="comment">/usr/bin/fdfs_appender_test</span>
<span class="literal">-</span><span class="comment">rwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span><span class="string">.</span> <span class="comment">1</span> <span class="comment">root</span> <span class="comment">root</span> <span class="comment">257424</span> <span class="comment">10月</span> <span class="comment">28</span> <span class="comment">11:29</span> <span class="comment">/usr/bin/fdfs_appender_test1</span>
<span class="literal">-</span><span class="comment">rwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span><span class="string">.</span> <span class="comment">1</span> <span class="comment">root</span> <span class="comment">root</span> <span class="comment">247664</span> <span class="comment">10月</span> <span class="comment">28</span> <span class="comment">11:29</span> <span class="comment">/usr/bin/fdfs_append_file</span>
<span class="literal">-</span><span class="comment">rwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span><span class="string">.</span> <span class="comment">1</span> <span class="comment">root</span> <span class="comment">root</span> <span class="comment">247340</span> <span class="comment">10月</span> <span class="comment">28</span> <span class="comment">11:29</span> <span class="comment">/usr/bin/fdfs_crc32</span>
<span class="literal">-</span><span class="comment">rwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span><span class="string">.</span> <span class="comment">1</span> <span class="comment">root</span> <span class="comment">root</span> <span class="comment">247723</span> <span class="comment">10月</span> <span class="comment">28</span> <span class="comment">11:29</span> <span class="comment">/usr/bin/fdfs_delete_file</span>
<span class="literal">-</span><span class="comment">rwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span><span class="string">.</span> <span class="comment">1</span> <span class="comment">root</span> <span class="comment">root</span> <span class="comment">248850</span> <span class="comment">10月</span> <span class="comment">28</span> <span class="comment">11:29</span> <span class="comment">/usr/bin/fdfs_download_file</span>
<span class="literal">-</span><span class="comment">rwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span><span class="string">.</span> <span class="comment">1</span> <span class="comment">root</span> <span class="comment">root</span> <span class="comment">248584</span> <span class="comment">10月</span> <span class="comment">28</span> <span class="comment">11:29</span> <span class="comment">/usr/bin/fdfs_file_info</span>
<span class="literal">-</span><span class="comment">rwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span><span class="string">.</span> <span class="comment">1</span> <span class="comment">root</span> <span class="comment">root</span> <span class="comment">260848</span> <span class="comment">10月</span> <span class="comment">28</span> <span class="comment">11:29</span> <span class="comment">/usr/bin/fdfs_monitor</span>
<span class="literal">-</span><span class="comment">rwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span><span class="string">.</span> <span class="comment">1</span> <span class="comment">root</span> <span class="comment">root</span> <span class="comment">886610</span> <span class="comment">10月</span> <span class="comment">28</span> <span class="comment">11:29</span> <span class="comment">/usr/bin/fdfs_storaged</span>
<span class="literal">-</span><span class="comment">rwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span><span class="string">.</span> <span class="comment">1</span> <span class="comment">root</span> <span class="comment">root</span> <span class="comment">264031</span> <span class="comment">10月</span> <span class="comment">28</span> <span class="comment">11:29</span> <span class="comment">/usr/bin/fdfs_test</span>
<span class="literal">-</span><span class="comment">rwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span><span class="string">.</span> <span class="comment">1</span> <span class="comment">root</span> <span class="comment">root</span> <span class="comment">263208</span> <span class="comment">10月</span> <span class="comment">28</span> <span class="comment">11:29</span> <span class="comment">/usr/bin/fdfs_test1</span>
<span class="literal">-</span><span class="comment">rwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span><span class="string">.</span> <span class="comment">1</span> <span class="comment">root</span> <span class="comment">root</span> <span class="comment">374872</span> <span class="comment">10月</span> <span class="comment">28</span> <span class="comment">11:29</span> <span class="comment">/usr/bin/fdfs_trackerd</span>
<span class="literal">-</span><span class="comment">rwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span><span class="string">.</span> <span class="comment">1</span> <span class="comment">root</span> <span class="comment">root</span> <span class="comment">248730</span> <span class="comment">10月</span> <span class="comment">28</span> <span class="comment">11:29</span> <span class="comment">/usr/bin/fdfs_upload_appender</span>
<span class="literal">-</span><span class="comment">rwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span><span class="string">.</span> <span class="comment">1</span> <span class="comment">root</span> <span class="comment">root</span> <span class="comment">249676</span> <span class="comment">10月</span> <span class="comment">28</span> <span class="comment">11:29</span> <span class="comment">/usr/bin/fdfs_upload_file</span>
<span class="title">[</span><span class="comment">root@tracker</span> <span class="comment">FastDFS</span><span class="title">]</span><span class="comment">#</span> 
</code></pre>

<p>所有的配置文件在 /etc/fdfs/ 目录下</p>

<pre><code class="brainfuck">
<span class="title">[</span><span class="comment">root@tracker</span> <span class="comment">FastDFS</span><span class="title">]</span><span class="comment">#</span> <span class="comment">ll</span> <span class="comment">/etc/fdfs/</span>
<span class="comment">总用量</span> <span class="comment">20</span>
<span class="literal">-</span><span class="comment">rw</span><span class="literal">-</span><span class="comment">r</span><span class="literal">-</span><span class="literal">-</span><span class="comment">r</span><span class="literal">-</span><span class="literal">-</span><span class="string">.</span> <span class="comment">1</span> <span class="comment">root</span> <span class="comment">root</span> <span class="comment">1461</span> <span class="comment">10月</span> <span class="comment">28</span> <span class="comment">11:29</span> <span class="comment">client</span><span class="string">.</span><span class="comment">conf</span><span class="string">.</span><span class="comment">sample</span>
<span class="literal">-</span><span class="comment">rw</span><span class="literal">-</span><span class="comment">r</span><span class="literal">-</span><span class="literal">-</span><span class="comment">r</span><span class="literal">-</span><span class="literal">-</span><span class="string">.</span> <span class="comment">1</span> <span class="comment">root</span> <span class="comment">root</span> <span class="comment">7647</span> <span class="comment">10月</span> <span class="comment">28</span> <span class="comment">11:29</span> <span class="comment">storage</span><span class="string">.</span><span class="comment">conf</span><span class="string">.</span><span class="comment">sample</span>
<span class="literal">-</span><span class="comment">rw</span><span class="literal">-</span><span class="comment">r</span><span class="literal">-</span><span class="literal">-</span><span class="comment">r</span><span class="literal">-</span><span class="literal">-</span><span class="string">.</span> <span class="comment">1</span> <span class="comment">root</span> <span class="comment">root</span> <span class="comment">7102</span> <span class="comment">10月</span> <span class="comment">28</span> <span class="comment">11:29</span> <span class="comment">tracker</span><span class="string">.</span><span class="comment">conf</span><span class="string">.</span><span class="comment">sample</span>
<span class="title">[</span><span class="comment">root@tracker</span> <span class="comment">FastDFS</span><span class="title">]</span><span class="comment">#</span> 
</code></pre>

<p>至此 FastDFS在tracker上安装完成，以下进行配置</p>

<h4>2. 配置</h4>

<p>进入到 /etc/fdfs 目录下，复制模版文件到  tracker.conf</p>

<pre><code class="ruby">
[root<span class="variable">@tracker</span> fdfs]<span class="comment"># cp tracker.conf.sample tracker.conf</span>
</code></pre>

<p>创建数据文件和日志文件目录</p>

<pre><code class="perl">
[root<span class="variable">@tracker</span> fdfs]<span class="comment"># mkdir -pv /data/fastdfs/tracker</span>
<span class="keyword">mkdir</span>: 已创建目录 <span class="string">"/data"</span>
<span class="keyword">mkdir</span>: 已创建目录 <span class="string">"/data/fastdfs"</span>
<span class="keyword">mkdir</span>: 已创建目录 <span class="string">"/data/fastdfs/tracker"</span>
</code></pre>

<p>编辑 tracker.conf 文件，测试的时候只需要修改以下参数即可</p>

<pre><code class="bash">
disabled=<span class="literal">false</span>                        <span class="comment">#启用配置文件</span>
port=<span class="number">22122</span>                            <span class="comment">#设置 tracker 的端口号</span>
base_path=/data/fastdfs/tracker       <span class="comment">#设置 tracker 的数据文件和日志目录（需预先创建）</span>
http.server_port=<span class="number">8080</span>                 <span class="comment">#设置 http 端口号</span>
</code></pre>

<p>这个http.server_port=8080 指的是在tracker服务器上启动http服务进程，如:apache或者nginx 启动时所监听的端口，这个似乎是可以不用管的，因为tracker本身就没有安装http服务</p>

<h4>3.运行</h4>

<p>直接使用 fdfs_trackerd 来启动tracker进程，然后使用netstat 查看端口是否起来。</p>

<pre><code class="ruby">
[root<span class="variable">@tracker</span> fdfs]<span class="comment"># fdfs_trackerd /etc/fdfs/tracker.conf restart</span>
[root<span class="variable">@tracker</span> fdfs]<span class="comment"># netstat -antp | grep trackerd</span>
tcp        <span class="number">0</span>      <span class="number">0</span> <span class="number">0</span>.<span class="number">0</span>.<span class="number">0</span>.<span class="number">0</span><span class="symbol">:</span><span class="number">22122</span>               <span class="number">0</span>.<span class="number">0</span>.<span class="number">0</span>.<span class="number">0</span><span class="symbol">:*</span>                   <span class="constant">LISTEN</span>      <span class="number">14520</span>/fdfs_trackerd 
[root<span class="variable">@tracker</span> fdfs]<span class="comment"># </span>
</code></pre>

<p>也可以查看日志看服务是否正常运行</p>

<pre><code class="brainfuck">
<span class="title">[</span><span class="comment">root@tracker</span> <span class="comment">tracker</span><span class="title">]</span><span class="comment">#</span> <span class="comment">cat</span> <span class="comment">/data/fastdfs/tracker/logs/trackerd</span><span class="string">.</span><span class="comment">log</span> 
<span class="title">[</span><span class="comment">2014</span><span class="literal">-</span><span class="comment">10</span><span class="literal">-</span><span class="comment">28</span> <span class="comment">13:53:43</span><span class="title">]</span> <span class="comment">INFO</span> <span class="literal">-</span> <span class="comment">FastDFS</span> <span class="comment">v5</span><span class="string">.</span><span class="comment">04</span><span class="string">,</span> <span class="comment">base_path=/data/fastdfs/tracker</span><span class="string">,</span> <span class="comment">run_by_group=</span><span class="string">,</span> <span class="comment">run_by_user=</span><span class="string">,</span> <span class="comment">connect_timeout=30s</span><span class="string">,</span> <span class="comment">network_timeout=60s</span><span class="string">,</span> <span class="comment">port=22122</span><span class="string">,</span> <span class="comment">bind_addr=</span><span class="string">,</span> <span class="comment">max_connections=256</span><span class="string">,</span> <span class="comment">accept_threads=1</span><span class="string">,</span> <span class="comment">work_threads=4</span><span class="string">,</span> <span class="comment">store_lookup=2</span><span class="string">,</span> <span class="comment">store_group=</span><span class="string">,</span> <span class="comment">store_server=0</span><span class="string">,</span> <span class="comment">store_path=0</span><span class="string">,</span> <span class="comment">reserved_storage_space=10</span><span class="string">.</span><span class="comment">00%</span><span class="string">,</span> <span class="comment">download_server=0</span><span class="string">,</span> <span class="comment">allow_ip_count=</span><span class="literal">-</span><span class="comment">1</span><span class="string">,</span> <span class="comment">sync_log_buff_interval=10s</span><span class="string">,</span> <span class="comment">check_active_interval=120s</span><span class="string">,</span> <span class="comment">thread_stack_size=64</span> <span class="comment">KB</span><span class="string">,</span> <span class="comment">storage_ip_changed_auto_adjust=1</span><span class="string">,</span> <span class="comment">storage_sync_file_max_delay=86400s</span><span class="string">,</span> <span class="comment">storage_sync_file_max_time=300s</span><span class="string">,</span> <span class="comment">use_trunk_file=0</span><span class="string">,</span> <span class="comment">slot_min_size=256</span><span class="string">,</span> <span class="comment">slot_max_size=16</span> <span class="comment">MB</span><span class="string">,</span> <span class="comment">trunk_file_size=64</span> <span class="comment">MB</span><span class="string">,</span> <span class="comment">trunk_create_file_advance=0</span><span class="string">,</span> <span class="comment">trunk_create_file_time_base=02:00</span><span class="string">,</span> <span class="comment">trunk_create_file_interval=86400</span><span class="string">,</span> <span class="comment">trunk_create_file_space_threshold=20</span> <span class="comment">GB</span><span class="string">,</span> <span class="comment">trunk_init_check_occupying=0</span><span class="string">,</span> <span class="comment">trunk_init_reload_from_binlog=0</span><span class="string">,</span> <span class="comment">trunk_compress_binlog_min_interval=0</span><span class="string">,</span> <span class="comment">use_storage_id=0</span><span class="string">,</span> <span class="comment">id_type_in_filename=ip</span><span class="string">,</span> <span class="comment">storage_id_count=0</span><span class="string">,</span> <span class="comment">rotate_error_log=0</span><span class="string">,</span> <span class="comment">error_log_rotate_time=00:00</span><span class="string">,</span> <span class="comment">rotate_error_log_size=0</span><span class="string">,</span> <span class="comment">log_file_keep_days=0</span><span class="string">,</span> <span class="comment">store_slave_file_use_link=0</span><span class="string">,</span> <span class="comment">use_connection_pool=0</span><span class="string">,</span> <span class="comment">g_connection_pool_max_idle_time=3600s</span>
<span class="title">[</span><span class="comment">2014</span><span class="literal">-</span><span class="comment">10</span><span class="literal">-</span><span class="comment">28</span> <span class="comment">13:53:43</span><span class="title">]</span> <span class="comment">INFO</span> <span class="literal">-</span> <span class="comment">local_host_ip_count:</span> <span class="comment">2</span><span class="string">,</span>  <span class="comment">127</span><span class="string">.</span><span class="comment">0</span><span class="string">.</span><span class="comment">0</span><span class="string">.</span><span class="comment">1</span>  <span class="comment">10</span><span class="string">.</span><span class="comment">10</span><span class="string">.</span><span class="comment">10</span><span class="string">.</span><span class="comment">124</span>
</code></pre>

<h4>4.设置开机自动启动</h4>

<pre><code class="bash">
[root@tracker tracker]<span class="comment"># echo "/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart" &gt;&gt; /etc/rc.local</span>
[root@tracker tracker]<span class="comment"># cat /etc/rc.local</span>
<span class="shebang">#!/bin/sh</span>
<span class="comment">#</span>
<span class="comment"># This script will be executed *after* all the other init scripts.</span>
<span class="comment"># You can put your own initialization stuff in here if you don't</span>
<span class="comment"># want to do the full Sys V style init stuff.</span>
touch /var/lock/subsys/local
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
[root@tracker tracker]<span class="comment"># </span>
</code></pre>

<p>至此tracker上的安装与配置结束。</p>

<h1>三、storage的安装与配置</h1>

<h4>1.安装</h4>

<p>以下操作是在 10.10.10.120 storage1上操作</p>

<p>利用上传 FastDFS_v5.04.tar.gz 和 libfastcommon-master.zip 至 storage服务器的/usr/local/src 目录下</p>

<pre><code class="brainfuck">
<span class="title">[</span><span class="comment">root@server1</span> <span class="comment">src</span><span class="title">]</span><span class="comment">#</span> <span class="comment">rz</span>
<span class="comment">rz</span> <span class="comment">waiting</span> <span class="comment">to</span> <span class="comment">receive</span><span class="string">.</span>
<span class="comment">Starting</span> <span class="comment">zmodem</span> <span class="comment">transfer</span><span class="string">.</span>  <span class="comment">Press</span> <span class="comment">Ctrl</span><span class="literal">+</span><span class="comment">C</span> <span class="comment">to</span> <span class="comment">cancel</span><span class="string">.</span>
<span class="comment">Transferring</span> <span class="comment">FastDFS_v5</span><span class="string">.</span><span class="comment">04</span><span class="string">.</span><span class="comment">tar</span><span class="string">.</span><span class="comment">gz</span><span class="string">.</span><span class="string">.</span><span class="string">.</span>
  <span class="comment">100%</span>     <span class="comment">335</span> <span class="comment">KB</span>     <span class="comment">335</span> <span class="comment">KB/sec</span>    <span class="comment">00:00:01</span>       <span class="comment">0</span> <span class="comment">Errors</span>  
<span class="title">[</span><span class="comment">root@server1</span> <span class="comment">src</span><span class="title">]</span><span class="comment">#</span> <span class="comment">ls</span>
<span class="comment">FastDFS_v5</span><span class="string">.</span><span class="comment">04</span><span class="string">.</span><span class="comment">tar</span><span class="string">.</span><span class="comment">gz</span>
<span class="title">[</span><span class="comment">root@server1</span> <span class="comment">src</span><span class="title">]</span><span class="comment">#</span> <span class="comment">rz</span>
<span class="comment">rz</span> <span class="comment">waiting</span> <span class="comment">to</span> <span class="comment">receive</span><span class="string">.</span>
<span class="comment">Starting</span> <span class="comment">zmodem</span> <span class="comment">transfer</span><span class="string">.</span>  <span class="comment">Press</span> <span class="comment">Ctrl</span><span class="literal">+</span><span class="comment">C</span> <span class="comment">to</span> <span class="comment">cancel</span><span class="string">.</span>
<span class="comment">Transferring</span> <span class="comment">libfastcommon</span><span class="literal">-</span><span class="comment">master</span><span class="string">.</span><span class="comment">zip</span><span class="string">.</span><span class="string">.</span><span class="string">.</span>
  <span class="comment">100%</span>      <span class="comment">95</span> <span class="comment">KB</span>      <span class="comment">95</span> <span class="comment">KB/sec</span>    <span class="comment">00:00:01</span>       <span class="comment">0</span> <span class="comment">Errors</span>  
<span class="title">[</span><span class="comment">root@server1</span> <span class="comment">src</span><span class="title">]</span><span class="comment">#</span> <span class="comment">ll</span>
<span class="comment">总用量</span> <span class="comment">432</span>
<span class="literal">-</span><span class="comment">rw</span><span class="literal">-</span><span class="comment">r</span><span class="literal">-</span><span class="literal">-</span><span class="comment">r</span><span class="literal">-</span><span class="literal">-</span> <span class="comment">1</span> <span class="comment">root</span> <span class="comment">root</span> <span class="comment">343477</span> <span class="comment">10月</span> <span class="comment">27</span> <span class="comment">09:26</span> <span class="comment">FastDFS_v5</span><span class="string">.</span><span class="comment">04</span><span class="string">.</span><span class="comment">tar</span><span class="string">.</span><span class="comment">gz</span>
<span class="literal">-</span><span class="comment">rw</span><span class="literal">-</span><span class="comment">r</span><span class="literal">-</span><span class="literal">-</span><span class="comment">r</span><span class="literal">-</span><span class="literal">-</span> <span class="comment">1</span> <span class="comment">root</span> <span class="comment">root</span>  <span class="comment">97548</span> <span class="comment">10月</span> <span class="comment">28</span> <span class="comment">11:14</span> <span class="comment">libfastcommon</span><span class="literal">-</span><span class="comment">master</span><span class="string">.</span><span class="comment">zip</span>
<span class="title">[</span><span class="comment">root@server1</span> <span class="comment">src</span><span class="title">]</span><span class="comment">#</span> 
</code></pre>

<p>解压安装 libfastcommon</p>

<pre><code class="brainfuck">
<span class="title">[</span><span class="comment">root@server1</span> <span class="comment">src</span><span class="title">]</span><span class="comment">#</span> <span class="comment">unzip</span> <span class="comment">libfastcommon</span><span class="literal">-</span><span class="comment">master</span><span class="string">.</span><span class="comment">zip</span> 
<span class="title">[</span><span class="comment">root@server1</span> <span class="comment">libfastcommon</span><span class="literal">-</span><span class="comment">master</span><span class="title">]</span><span class="comment">#</span> <span class="comment">ll</span>
<span class="comment">总用量</span> <span class="comment">24</span>
<span class="literal">-</span><span class="comment">rw</span><span class="literal">-</span><span class="comment">r</span><span class="literal">-</span><span class="literal">-</span><span class="comment">r</span><span class="literal">-</span><span class="literal">-</span> <span class="comment">1</span> <span class="comment">root</span> <span class="comment">root</span> <span class="comment">2397</span> <span class="comment">10月</span> <span class="comment">26</span> <span class="comment">11:53</span> <span class="comment">HISTORY</span>
<span class="literal">-</span><span class="comment">rw</span><span class="literal">-</span><span class="comment">r</span><span class="literal">-</span><span class="literal">-</span><span class="comment">r</span><span class="literal">-</span><span class="literal">-</span> <span class="comment">1</span> <span class="comment">root</span> <span class="comment">root</span>  <span class="comment">582</span> <span class="comment">10月</span> <span class="comment">26</span> <span class="comment">11:53</span> <span class="comment">INSTALL</span>
<span class="literal">-</span><span class="comment">rw</span><span class="literal">-</span><span class="comment">r</span><span class="literal">-</span><span class="literal">-</span><span class="comment">r</span><span class="literal">-</span><span class="literal">-</span> <span class="comment">1</span> <span class="comment">root</span> <span class="comment">root</span> <span class="comment">1341</span> <span class="comment">10月</span> <span class="comment">26</span> <span class="comment">11:53</span> <span class="comment">libfastcommon</span><span class="string">.</span><span class="comment">spec</span>
<span class="literal">-</span><span class="comment">rwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span> <span class="comment">1</span> <span class="comment">root</span> <span class="comment">root</span> <span class="comment">2151</span> <span class="comment">10月</span> <span class="comment">26</span> <span class="comment">11:53</span> <span class="comment">make</span><span class="string">.</span><span class="comment">sh</span>
<span class="literal">-</span><span class="comment">rw</span><span class="literal">-</span><span class="comment">r</span><span class="literal">-</span><span class="literal">-</span><span class="comment">r</span><span class="literal">-</span><span class="literal">-</span> <span class="comment">1</span> <span class="comment">root</span> <span class="comment">root</span>  <span class="comment">617</span> <span class="comment">10月</span> <span class="comment">26</span> <span class="comment">11:53</span> <span class="comment">README</span>
<span class="comment">drwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span> <span class="comment">2</span> <span class="comment">root</span> <span class="comment">root</span> <span class="comment">4096</span> <span class="comment">10月</span> <span class="comment">26</span> <span class="comment">11:53</span> <span class="comment">src</span>
<span class="title">[</span><span class="comment">root@server1</span> <span class="comment">libfastcommon</span><span class="literal">-</span><span class="comment">master</span><span class="title">]</span><span class="comment">#</span> <span class="string">.</span><span class="comment">/make</span><span class="string">.</span><span class="comment">sh</span> 
<span class="comment">cc</span> <span class="literal">-</span><span class="comment">Wall</span> <span class="literal">-</span><span class="comment">D_FILE_OFFSET_BITS=64</span> <span class="literal">-</span><span class="comment">g</span> <span class="literal">-</span><span class="comment">DDEBUG_FLAG</span> <span class="literal">-</span><span class="comment">DOS_LINUX</span> <span class="literal">-</span><span class="comment">DIOEVENT_USE_EPOLL</span> <span class="literal">-</span><span class="comment">c</span> <span class="literal">-</span><span class="comment">fPIC</span> <span class="literal">-</span><span class="comment">o</span> <span class="comment">hash</span><span class="string">.</span><span class="comment">lo</span> <span class="comment">hash</span><span class="string">.</span><span class="comment">c</span>  
<span class="comment">cc</span> <span class="literal">-</span><span class="comment">Wall</span> <span class="literal">-</span><span class="comment">D_FILE_OFFSET_BITS=64</span> <span class="literal">-</span><span class="comment">g</span> <span class="literal">-</span><span class="comment">DDEBUG_FLAG</span> <span class="literal">-</span><span class="comment">DOS_LINUX</span> <span class="literal">-</span><span class="comment">DIOEVENT_USE_EPOLL</span> <span class="literal">-</span><span class="comment">c</span> <span class="literal">-</span><span class="comment">fPIC</span> <span class="literal">-</span><span class="comment">o</span> <span class="comment">chain</span><span class="string">.</span><span class="comment">lo</span> <span class="comment">chain</span><span class="string">.</span><span class="comment">c</span>  
<span class="comment">cc</span> <span class="literal">-</span><span class="comment">Wall</span> <span class="literal">-</span><span class="comment">D_FILE_OFFSET_BITS=64</span> <span class="literal">-</span><span class="comment">g</span> <span class="literal">-</span><span class="comment">DDEBUG_FLAG</span> <span class="literal">-</span><span class="comment">DOS_LINUX</span> <span class="literal">-</span><span class="comment">DIOEVENT_USE_EPOLL</span> <span class="literal">-</span><span class="comment">c</span> <span class="literal">-</span><span class="comment">fPIC</span> <span class="literal">-</span><span class="comment">o</span> <span class="comment">shared_func</span><span class="string">.</span><span class="comment">lo</span> <span class="comment">shared_func</span><span class="string">.</span><span class="comment">c</span>  
<span class="comment">cc</span> <span class="literal">-</span><span class="comment">Wall</span> <span class="literal">-</span><span class="comment">D_FILE_OFFSET_BITS=64</span> <span class="literal">-</span><span class="comment">g</span> <span class="literal">-</span><span class="comment">DDEBUG_FLAG</span> <span class="literal">-</span><span class="comment">DOS_LINUX</span> <span class="literal">-</span><span class="comment">DIOEVENT_USE_EPOLL</span> <span class="literal">-</span><span class="comment">c</span> <span class="literal">-</span><span class="comment">fPIC</span> <span class="literal">-</span><span class="comment">o</span> <span class="comment">ini_file_reader</span><span class="string">.</span><span class="comment">lo</span> <span class="comment">ini_file_reader</span><span class="string">.</span><span class="comment">c</span>  
<span class="comment">cc</span> <span class="literal">-</span><span class="comment">Wall</span> <span class="literal">-</span><span class="comment">D_FILE_OFFSET_BITS=64</span> <span class="literal">-</span><span class="comment">g</span> <span class="literal">-</span><span class="comment">DDEBUG_FLAG</span> <span class="literal">-</span><span class="comment">DOS_LINUX</span> <span class="literal">-</span><span class="comment">DIOEVENT_USE_EPOLL</span> <span class="literal">-</span><span class="comment">c</span> <span class="literal">-</span><span class="comment">fPIC</span> <span class="literal">-</span><span class="comment">o</span> <span class="comment">logger</span><span class="string">.</span><span class="comment">lo</span> <span class="comment">logger</span><span class="string">.</span><span class="comment">c</span>  
<span class="comment">cc</span> <span class="literal">-</span><span class="comment">Wall</span> <span class="literal">-</span><span class="comment">D_FILE_OFFSET_BITS=64</span> <span class="literal">-</span><span class="comment">g</span> <span class="literal">-</span><span class="comment">DDEBUG_FLAG</span> <span class="literal">-</span><span class="comment">DOS_LINUX</span> <span class="literal">-</span><span class="comment">DIOEVENT_USE_EPOLL</span> <span class="literal">-</span><span class="comment">c</span> <span class="literal">-</span><span class="comment">fPIC</span> <span class="literal">-</span><span class="comment">o</span> <span class="comment">sockopt</span><span class="string">.</span><span class="comment">lo</span> <span class="comment">sockopt</span><span class="string">.</span><span class="comment">c</span>  
<span class="comment">cc</span> <span class="literal">-</span><span class="comment">Wall</span> <span class="literal">-</span><span class="comment">D_FILE_OFFSET_BITS=64</span> <span class="literal">-</span><span class="comment">g</span> <span class="literal">-</span><span class="comment">DDEBUG_FLAG</span> <span class="literal">-</span><span class="comment">DOS_LINUX</span> <span class="literal">-</span><span class="comment">DIOEVENT_USE_EPOLL</span> <span class="literal">-</span><span class="comment">c</span> <span class="literal">-</span><span class="comment">fPIC</span> <span class="literal">-</span><span class="comment">o</span> <span class="comment">base64</span><span class="string">.</span><span class="comment">lo</span> <span class="comment">base64</span><span class="string">.</span><span class="comment">c</span>  
<span class="string">.</span><span class="string">.</span><span class="string">.</span>
<span class="title">[</span><span class="comment">root@server1</span> <span class="comment">libfastcommon</span><span class="literal">-</span><span class="comment">master</span><span class="title">]</span><span class="comment">#</span> <span class="string">.</span><span class="comment">/make</span><span class="string">.</span><span class="comment">sh</span> <span class="comment">install</span>
<span class="comment">mkdir</span> <span class="literal">-</span><span class="comment">p</span> <span class="comment">/usr/lib64</span>
<span class="comment">install</span> <span class="literal">-</span><span class="comment">m</span> <span class="comment">755</span> <span class="comment">libfastcommon</span><span class="string">.</span><span class="comment">so</span> <span class="comment">/usr/lib64</span>
<span class="comment">mkdir</span> <span class="literal">-</span><span class="comment">p</span> <span class="comment">/usr/include/fastcommon</span>
<span class="comment">install</span> <span class="literal">-</span><span class="comment">m</span> <span class="comment">644</span> <span class="comment">common_define</span><span class="string">.</span><span class="comment">h</span> <span class="comment">hash</span><span class="string">.</span><span class="comment">h</span> <span class="comment">chain</span><span class="string">.</span><span class="comment">h</span> <span class="comment">logger</span><span class="string">.</span><span class="comment">h</span> <span class="comment">base64</span><span class="string">.</span><span class="comment">h</span> <span class="comment">shared_func</span><span class="string">.</span><span class="comment">h</span> <span class="comment">pthread_func</span><span class="string">.</span><span class="comment">h</span> <span class="comment">ini_file_reader</span><span class="string">.</span><span class="comment">h</span> <span class="comment">_os_bits</span><span class="string">.</span><span class="comment">h</span> <span class="comment">sockopt</span><span class="string">.</span><span class="comment">h</span> <span class="comment">sched_thread</span><span class="string">.</span><span class="comment">h</span> <span class="comment">http_func</span><span class="string">.</span><span class="comment">h</span> <span class="comment">md5</span><span class="string">.</span><span class="comment">h</span> <span class="comment">local_ip_func</span><span class="string">.</span><span class="comment">h</span> <span class="comment">avl_tree</span><span class="string">.</span><span class="comment">h</span> <span class="comment">ioevent</span><span class="string">.</span><span class="comment">h</span> <span class="comment">ioevent_loop</span><span class="string">.</span><span class="comment">h</span> <span class="comment">fast_task_queue</span><span class="string">.</span><span class="comment">h</span> <span class="comment">fast_timer</span><span class="string">.</span><span class="comment">h</span> <span class="comment">process_ctrl</span><span class="string">.</span><span class="comment">h</span> <span class="comment">fast_mblock</span><span class="string">.</span><span class="comment">h</span> <span class="comment">connection_pool</span><span class="string">.</span><span class="comment">h</span> <span class="comment">/usr/include/fastcommon</span>
</code></pre>

<p>解压安装 FastDFS_v5.04.tar.gz</p>

<pre><code class="brainfuck">
<span class="title">[</span><span class="comment">root@server1</span> <span class="comment">src</span><span class="title">]</span><span class="comment">#</span> <span class="comment">tar</span> <span class="comment">xf</span> <span class="comment">FastDFS_v5</span><span class="string">.</span><span class="comment">04</span><span class="string">.</span><span class="comment">tar</span><span class="string">.</span><span class="comment">gz</span> 
<span class="title">[</span><span class="comment">root@server1</span> <span class="comment">src</span><span class="title">]</span><span class="comment">#</span> <span class="comment">cd</span> <span class="comment">FastDFS</span>
<span class="title">[</span><span class="comment">root@server1</span> <span class="comment">FastDFS</span><span class="title">]</span><span class="comment">#</span> <span class="comment">ll</span>
<span class="comment">总用量</span> <span class="comment">132</span>
<span class="comment">drwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span> <span class="comment">3</span> <span class="comment">8980</span> <span class="comment">users</span>  <span class="comment">4096</span> <span class="comment">9月</span>  <span class="comment">21</span> <span class="comment">22:14</span> <span class="comment">client</span>
<span class="comment">drwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span> <span class="comment">2</span> <span class="comment">8980</span> <span class="comment">users</span>  <span class="comment">4096</span> <span class="comment">9月</span>  <span class="comment">21</span> <span class="comment">22:14</span> <span class="comment">common</span>
<span class="comment">drwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span> <span class="comment">2</span> <span class="comment">8980</span> <span class="comment">users</span>  <span class="comment">4096</span> <span class="comment">9月</span>  <span class="comment">21</span> <span class="comment">22:14</span> <span class="comment">conf</span>
<span class="literal">-</span><span class="comment">rw</span><span class="literal">-</span><span class="comment">r</span><span class="literal">-</span><span class="literal">-</span><span class="comment">r</span><span class="literal">-</span><span class="literal">-</span> <span class="comment">1</span> <span class="comment">8980</span> <span class="comment">users</span> <span class="comment">35067</span> <span class="comment">9月</span>  <span class="comment">21</span> <span class="comment">22:14</span> <span class="comment">COPYING</span><span class="literal">-</span><span class="comment">3_0</span><span class="string">.</span><span class="comment">txt</span>
<span class="literal">-</span><span class="comment">rw</span><span class="literal">-</span><span class="comment">r</span><span class="literal">-</span><span class="literal">-</span><span class="comment">r</span><span class="literal">-</span><span class="literal">-</span> <span class="comment">1</span> <span class="comment">8980</span> <span class="comment">users</span>  <span class="comment">2802</span> <span class="comment">9月</span>  <span class="comment">21</span> <span class="comment">22:14</span> <span class="comment">fastdfs</span><span class="string">.</span><span class="comment">spec</span>
<span class="literal">-</span><span class="comment">rw</span><span class="literal">-</span><span class="comment">r</span><span class="literal">-</span><span class="literal">-</span><span class="comment">r</span><span class="literal">-</span><span class="literal">-</span> <span class="comment">1</span> <span class="comment">8980</span> <span class="comment">users</span> <span class="comment">31224</span> <span class="comment">9月</span>  <span class="comment">21</span> <span class="comment">22:14</span> <span class="comment">HISTORY</span>
<span class="comment">drwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span> <span class="comment">2</span> <span class="comment">8980</span> <span class="comment">users</span>  <span class="comment">4096</span> <span class="comment">9月</span>  <span class="comment">21</span> <span class="comment">22:14</span> <span class="comment">init</span><span class="string">.</span><span class="comment">d</span>
<span class="literal">-</span><span class="comment">rw</span><span class="literal">-</span><span class="comment">r</span><span class="literal">-</span><span class="literal">-</span><span class="comment">r</span><span class="literal">-</span><span class="literal">-</span> <span class="comment">1</span> <span class="comment">8980</span> <span class="comment">users</span>  <span class="comment">7755</span> <span class="comment">9月</span>  <span class="comment">21</span> <span class="comment">22:14</span> <span class="comment">INSTALL</span>
<span class="literal">-</span><span class="comment">rwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span> <span class="comment">1</span> <span class="comment">8980</span> <span class="comment">users</span>  <span class="comment">5735</span> <span class="comment">9月</span>  <span class="comment">21</span> <span class="comment">22:14</span> <span class="comment">make</span><span class="string">.</span><span class="comment">sh</span>
<span class="comment">drwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span> <span class="comment">2</span> <span class="comment">8980</span> <span class="comment">users</span>  <span class="comment">4096</span> <span class="comment">9月</span>  <span class="comment">21</span> <span class="comment">22:14</span> <span class="comment">php_client</span>
<span class="literal">-</span><span class="comment">rw</span><span class="literal">-</span><span class="comment">r</span><span class="literal">-</span><span class="literal">-</span><span class="comment">r</span><span class="literal">-</span><span class="literal">-</span> <span class="comment">1</span> <span class="comment">8980</span> <span class="comment">users</span>  <span class="comment">2380</span> <span class="comment">9月</span>  <span class="comment">21</span> <span class="comment">22:14</span> <span class="comment">README</span><span class="string">.</span><span class="comment">md</span>
<span class="literal">-</span><span class="comment">rwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span> <span class="comment">1</span> <span class="comment">8980</span> <span class="comment">users</span>  <span class="comment">1768</span> <span class="comment">9月</span>  <span class="comment">21</span> <span class="comment">22:14</span> <span class="comment">restart</span><span class="string">.</span><span class="comment">sh</span>
<span class="literal">-</span><span class="comment">rwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span> <span class="comment">1</span> <span class="comment">8980</span> <span class="comment">users</span>  <span class="comment">1680</span> <span class="comment">9月</span>  <span class="comment">21</span> <span class="comment">22:14</span> <span class="comment">stop</span><span class="string">.</span><span class="comment">sh</span>
<span class="comment">drwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span> <span class="comment">4</span> <span class="comment">8980</span> <span class="comment">users</span>  <span class="comment">4096</span> <span class="comment">9月</span>  <span class="comment">21</span> <span class="comment">22:14</span> <span class="comment">storage</span>
<span class="comment">drwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span> <span class="comment">2</span> <span class="comment">8980</span> <span class="comment">users</span>  <span class="comment">4096</span> <span class="comment">9月</span>  <span class="comment">21</span> <span class="comment">22:14</span> <span class="comment">test</span>
<span class="comment">drwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span> <span class="comment">2</span> <span class="comment">8980</span> <span class="comment">users</span>  <span class="comment">4096</span> <span class="comment">9月</span>  <span class="comment">21</span> <span class="comment">22:14</span> <span class="comment">tracker</span>
<span class="title">[</span><span class="comment">root@server1</span> <span class="comment">FastDFS</span><span class="title">]</span><span class="comment">#</span> 
<span class="title">[</span><span class="comment">root@server1</span> <span class="comment">FastDFS</span><span class="title">]</span><span class="comment">#</span> <span class="string">.</span><span class="comment">/make</span><span class="string">.</span><span class="comment">sh</span> 
<span class="comment">cc</span> <span class="literal">-</span><span class="comment">Wall</span> <span class="literal">-</span><span class="comment">D_FILE_OFFSET_BITS=64</span> <span class="literal">-</span><span class="comment">D_GNU_SOURCE</span> <span class="literal">-</span><span class="comment">g</span> <span class="literal">-</span><span class="comment">O</span> <span class="literal">-</span><span class="comment">DDEBUG_FLAG</span> <span class="literal">-</span><span class="comment">DOS_LINUX</span> <span class="literal">-</span><span class="comment">DIOEVENT_USE_EPOLL</span> <span class="literal">-</span><span class="comment">c</span> <span class="literal">-</span><span class="comment">o</span> <span class="string">.</span><span class="string">.</span><span class="comment">/common/fdfs_global</span><span class="string">.</span><span class="comment">o</span> <span class="string">.</span><span class="string">.</span><span class="comment">/common/fdfs_global</span><span class="string">.</span><span class="comment">c</span>  <span class="literal">-</span><span class="comment">I</span><span class="string">.</span><span class="string">.</span><span class="comment">/common</span> <span class="literal">-</span><span class="comment">I/usr/include/fastcommon</span>
<span class="comment">cc</span> <span class="literal">-</span><span class="comment">Wall</span> <span class="literal">-</span><span class="comment">D_FILE_OFFSET_BITS=64</span> <span class="literal">-</span><span class="comment">D_GNU_SOURCE</span> <span class="literal">-</span><span class="comment">g</span> <span class="literal">-</span><span class="comment">O</span> <span class="literal">-</span><span class="comment">DDEBUG_FLAG</span> <span class="literal">-</span><span class="comment">DOS_LINUX</span> <span class="literal">-</span><span class="comment">DIOEVENT_USE_EPOLL</span> <span class="literal">-</span><span class="comment">c</span> <span class="literal">-</span><span class="comment">o</span> <span class="comment">tracker_proto</span><span class="string">.</span><span class="comment">o</span> <span class="comment">tracker_proto</span><span class="string">.</span><span class="comment">c</span>  <span class="literal">-</span><span class="comment">I</span><span class="string">.</span><span class="string">.</span><span class="comment">/common</span> <span class="literal">-</span><span class="comment">I/usr/include/fastcommon</span>
<span class="comment">cc</span> <span class="literal">-</span><span class="comment">Wall</span> <span class="literal">-</span><span class="comment">D_FILE_OFFSET_BITS=64</span> <span class="literal">-</span><span class="comment">D_GNU_SOURCE</span> <span class="literal">-</span><span class="comment">g</span> <span class="literal">-</span><span class="comment">O</span> <span class="literal">-</span><span class="comment">DDEBUG_FLAG</span> <span class="literal">-</span><span class="comment">DOS_LINUX</span> <span class="literal">-</span><span class="comment">DIOEVENT_USE_EPOLL</span> <span class="literal">-</span><span class="comment">c</span> <span class="literal">-</span><span class="comment">o</span> <span class="comment">tracker_mem</span><span class="string">.</span><span class="comment">o</span> <span class="comment">tracker_mem</span><span class="string">.</span><span class="comment">c</span>  <span class="literal">-</span><span class="comment">I</span><span class="string">.</span><span class="string">.</span><span class="comment">/common</span> <span class="literal">-</span><span class="comment">I/usr/include/fastcommon</span>
<span class="comment">cc</span> <span class="literal">-</span><span class="comment">Wall</span> <span class="literal">-</span><span class="comment">D_FILE_OFFSET_BITS=64</span> <span class="literal">-</span><span class="comment">D_GNU_SOURCE</span> <span class="literal">-</span><span class="comment">g</span> <span class="literal">-</span><span class="comment">O</span> <span class="literal">-</span><span class="comment">DDEBUG_FLAG</span> <span class="literal">-</span><span class="comment">DOS_LINUX</span> <span class="literal">-</span><span class="comment">DIOEVENT_USE_EPOLL</span> <span class="literal">-</span><span class="comment">c</span> <span class="literal">-</span><span class="comment">o</span> <span class="comment">tracker_service</span><span class="string">.</span><span class="comment">o</span> <span class="comment">tracker_service</span><span class="string">.</span><span class="comment">c</span>  <span class="literal">-</span><span class="comment">I</span><span class="string">.</span><span class="string">.</span><span class="comment">/common</span> <span class="literal">-</span><span class="comment">I/usr/include/fastcommon</span>
<span class="comment">cc</span> <span class="literal">-</span><span class="comment">Wall</span> <span class="literal">-</span><span class="comment">D_FILE_OFFSET_BITS=64</span> <span class="literal">-</span><span class="comment">D_GNU_SOURCE</span> <span class="literal">-</span><span class="comment">g</span> <span class="literal">-</span><span class="comment">O</span> <span class="literal">-</span><span class="comment">DDEBUG_FLAG</span> <span class="literal">-</span><span class="comment">DOS_LINUX</span> <span class="literal">-</span><span class="comment">DIOEVENT_USE_EPOLL</span> <span class="literal">-</span><span class="comment">c</span> <span class="literal">-</span><span class="comment">o</span> <span class="comment">tracker_status</span><span class="string">.</span><span class="comment">o</span> <span class="comment">tracker_status</span><span class="string">.</span><span class="comment">c</span>  <span class="literal">-</span><span class="comment">I</span><span class="string">.</span><span class="string">.</span><span class="comment">/common</span> <span class="literal">-</span><span class="comment">I/usr/include/fastcommon</span>
<span class="string">.</span><span class="string">.</span><span class="string">.</span>
<span class="title">[</span><span class="comment">root@server1</span> <span class="comment">FastDFS</span><span class="title">]</span><span class="comment">#</span> <span class="string">.</span><span class="comment">/make</span><span class="string">.</span><span class="comment">sh</span> <span class="comment">install</span>
<span class="comment">mkdir</span> <span class="literal">-</span><span class="comment">p</span> <span class="comment">/usr/bin</span>
<span class="comment">mkdir</span> <span class="literal">-</span><span class="comment">p</span> <span class="comment">/etc/fdfs</span>
<span class="comment">cp</span> <span class="literal">-</span><span class="comment">f</span> <span class="comment">fdfs_trackerd</span> <span class="comment">/usr/bin</span>
<span class="comment">if</span> <span class="title">[</span> <span class="comment">!</span> <span class="literal">-</span><span class="comment">f</span> <span class="comment">/etc/fdfs/tracker</span><span class="string">.</span><span class="comment">conf</span><span class="string">.</span><span class="comment">sample</span> <span class="title">]</span><span class="comment">;</span> <span class="comment">then</span> <span class="comment">cp</span> <span class="literal">-</span><span class="comment">f</span> <span class="string">.</span><span class="string">.</span><span class="comment">/conf/tracker</span><span class="string">.</span><span class="comment">conf</span> <span class="comment">/etc/fdfs/tracker</span><span class="string">.</span><span class="comment">conf</span><span class="string">.</span><span class="comment">sample;</span> <span class="comment">fi</span>
<span class="comment">mkdir</span> <span class="literal">-</span><span class="comment">p</span> <span class="comment">/usr/bin</span>
<span class="comment">mkdir</span> <span class="literal">-</span><span class="comment">p</span> <span class="comment">/etc/fdfs</span>
<span class="comment">cp</span> <span class="literal">-</span><span class="comment">f</span> <span class="comment">fdfs_storaged</span>  <span class="comment">/usr/bin</span>
<span class="comment">if</span> <span class="title">[</span> <span class="comment">!</span> <span class="literal">-</span><span class="comment">f</span> <span class="comment">/etc/fdfs/storage</span><span class="string">.</span><span class="comment">conf</span><span class="string">.</span><span class="comment">sample</span> <span class="title">]</span><span class="comment">;</span> <span class="comment">then</span> <span class="comment">cp</span> <span class="literal">-</span><span class="comment">f</span> <span class="string">.</span><span class="string">.</span><span class="comment">/conf/storage</span><span class="string">.</span><span class="comment">conf</span> <span class="comment">/etc/fdfs/storage</span><span class="string">.</span><span class="comment">conf</span><span class="string">.</span><span class="comment">sample;</span> <span class="comment">fi</span>
<span class="comment">mkdir</span> <span class="literal">-</span><span class="comment">p</span> <span class="comment">/usr/bin</span>
<span class="comment">mkdir</span> <span class="literal">-</span><span class="comment">p</span> <span class="comment">/etc/fdfs</span>
<span class="comment">mkdir</span> <span class="literal">-</span><span class="comment">p</span> <span class="comment">/usr/lib64</span>
<span class="comment">cp</span> <span class="literal">-</span><span class="comment">f</span> <span class="comment">fdfs_monitor</span> <span class="comment">fdfs_test</span> <span class="comment">fdfs_test1</span> <span class="comment">fdfs_crc32</span> <span class="comment">fdfs_upload_file</span> <span class="comment">fdfs_download_file</span> <span class="comment">fdfs_delete_file</span> <span class="comment">fdfs_file_info</span> <span class="comment">fdfs_appender_test</span> <span class="comment">fdfs_appender_test1</span> <span class="comment">fdfs_append_file</span> <span class="comment">fdfs_upload_appender</span> <span class="comment">/usr/bin</span>
<span class="comment">if</span> <span class="title">[</span> <span class="comment">0</span> <span class="literal">-</span><span class="comment">eq</span> <span class="comment">1</span> <span class="title">]</span><span class="comment">;</span> <span class="comment">then</span> <span class="comment">cp</span> <span class="literal">-</span><span class="comment">f</span> <span class="comment">libfdfsclient</span><span class="string">.</span><span class="comment">a</span> <span class="comment">/usr/lib64;</span> <span class="comment">fi</span>
<span class="comment">if</span> <span class="title">[</span> <span class="comment">1</span> <span class="literal">-</span><span class="comment">eq</span> <span class="comment">1</span> <span class="title">]</span><span class="comment">;</span> <span class="comment">then</span> <span class="comment">cp</span> <span class="literal">-</span><span class="comment">f</span> <span class="comment">libfdfsclient</span><span class="string">.</span><span class="comment">so</span> <span class="comment">/usr/lib64;</span> <span class="comment">fi</span>
<span class="comment">mkdir</span> <span class="literal">-</span><span class="comment">p</span> <span class="comment">/usr/include/fastdfs</span>
<span class="comment">cp</span> <span class="literal">-</span><span class="comment">f</span> <span class="string">.</span><span class="string">.</span><span class="comment">/common/fdfs_define</span><span class="string">.</span><span class="comment">h</span> <span class="string">.</span><span class="string">.</span><span class="comment">/common/fdfs_global</span><span class="string">.</span><span class="comment">h</span> <span class="string">.</span><span class="string">.</span><span class="comment">/common/mime_file_parser</span><span class="string">.</span><span class="comment">h</span> <span class="string">.</span><span class="string">.</span><span class="comment">/common/fdfs_http_shared</span><span class="string">.</span><span class="comment">h</span> <span class="string">.</span><span class="string">.</span><span class="comment">/tracker/tracker_types</span><span class="string">.</span><span class="comment">h</span> <span class="string">.</span><span class="string">.</span><span class="comment">/tracker/tracker_proto</span><span class="string">.</span><span class="comment">h</span> <span class="string">.</span><span class="string">.</span><span class="comment">/tracker/fdfs_shared_func</span><span class="string">.</span><span class="comment">h</span> <span class="string">.</span><span class="string">.</span><span class="comment">/storage/trunk_mgr/trunk_shared</span><span class="string">.</span><span class="comment">h</span> <span class="comment">tracker_client</span><span class="string">.</span><span class="comment">h</span> <span class="comment">storage_client</span><span class="string">.</span><span class="comment">h</span> <span class="comment">storage_client1</span><span class="string">.</span><span class="comment">h</span> <span class="comment">client_func</span><span class="string">.</span><span class="comment">h</span> <span class="comment">client_global</span><span class="string">.</span><span class="comment">h</span> <span class="comment">fdfs_client</span><span class="string">.</span><span class="comment">h</span> <span class="comment">/usr/include/fastdfs</span>
<span class="comment">if</span> <span class="title">[</span> <span class="comment">!</span> <span class="literal">-</span><span class="comment">f</span> <span class="comment">/etc/fdfs/client</span><span class="string">.</span><span class="comment">conf</span><span class="string">.</span><span class="comment">sample</span> <span class="title">]</span><span class="comment">;</span> <span class="comment">then</span> <span class="comment">cp</span> <span class="literal">-</span><span class="comment">f</span> <span class="string">.</span><span class="string">.</span><span class="comment">/conf/client</span><span class="string">.</span><span class="comment">conf</span> <span class="comment">/etc/fdfs/client</span><span class="string">.</span><span class="comment">conf</span><span class="string">.</span><span class="comment">sample;</span> <span class="comment">fi</span>
</code></pre>

<p>安装完成后，可执行文件在/usr/bin/下以 fdfs 开头</p>

<pre><code class="brainfuck">
<span class="title">[</span><span class="comment">root@server1</span> <span class="comment">FastDFS</span><span class="title">]</span><span class="comment">#</span> <span class="comment">ll</span> <span class="comment">/usr/bin/fdfs_*</span>
<span class="literal">-</span><span class="comment">rwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span> <span class="comment">1</span> <span class="comment">root</span> <span class="comment">root</span> <span class="comment">257631</span> <span class="comment">10月</span> <span class="comment">28</span> <span class="comment">14:18</span> <span class="comment">/usr/bin/fdfs_appender_test</span>
<span class="literal">-</span><span class="comment">rwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span> <span class="comment">1</span> <span class="comment">root</span> <span class="comment">root</span> <span class="comment">257424</span> <span class="comment">10月</span> <span class="comment">28</span> <span class="comment">14:18</span> <span class="comment">/usr/bin/fdfs_appender_test1</span>
<span class="literal">-</span><span class="comment">rwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span> <span class="comment">1</span> <span class="comment">root</span> <span class="comment">root</span> <span class="comment">247664</span> <span class="comment">10月</span> <span class="comment">28</span> <span class="comment">14:18</span> <span class="comment">/usr/bin/fdfs_append_file</span>
<span class="literal">-</span><span class="comment">rwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span> <span class="comment">1</span> <span class="comment">root</span> <span class="comment">root</span> <span class="comment">247340</span> <span class="comment">10月</span> <span class="comment">28</span> <span class="comment">14:18</span> <span class="comment">/usr/bin/fdfs_crc32</span>
<span class="literal">-</span><span class="comment">rwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span> <span class="comment">1</span> <span class="comment">root</span> <span class="comment">root</span> <span class="comment">247723</span> <span class="comment">10月</span> <span class="comment">28</span> <span class="comment">14:18</span> <span class="comment">/usr/bin/fdfs_delete_file</span>
<span class="literal">-</span><span class="comment">rwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span> <span class="comment">1</span> <span class="comment">root</span> <span class="comment">root</span> <span class="comment">248850</span> <span class="comment">10月</span> <span class="comment">28</span> <span class="comment">14:18</span> <span class="comment">/usr/bin/fdfs_download_file</span>
<span class="literal">-</span><span class="comment">rwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span> <span class="comment">1</span> <span class="comment">root</span> <span class="comment">root</span> <span class="comment">248584</span> <span class="comment">10月</span> <span class="comment">28</span> <span class="comment">14:18</span> <span class="comment">/usr/bin/fdfs_file_info</span>
<span class="literal">-</span><span class="comment">rwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span> <span class="comment">1</span> <span class="comment">root</span> <span class="comment">root</span> <span class="comment">260848</span> <span class="comment">10月</span> <span class="comment">28</span> <span class="comment">14:18</span> <span class="comment">/usr/bin/fdfs_monitor</span>
<span class="literal">-</span><span class="comment">rwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span> <span class="comment">1</span> <span class="comment">root</span> <span class="comment">root</span> <span class="comment">886610</span> <span class="comment">10月</span> <span class="comment">28</span> <span class="comment">14:18</span> <span class="comment">/usr/bin/fdfs_storaged</span>
<span class="literal">-</span><span class="comment">rwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span> <span class="comment">1</span> <span class="comment">root</span> <span class="comment">root</span> <span class="comment">264031</span> <span class="comment">10月</span> <span class="comment">28</span> <span class="comment">14:18</span> <span class="comment">/usr/bin/fdfs_test</span>
<span class="literal">-</span><span class="comment">rwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span> <span class="comment">1</span> <span class="comment">root</span> <span class="comment">root</span> <span class="comment">263208</span> <span class="comment">10月</span> <span class="comment">28</span> <span class="comment">14:18</span> <span class="comment">/usr/bin/fdfs_test1</span>
<span class="literal">-</span><span class="comment">rwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span> <span class="comment">1</span> <span class="comment">root</span> <span class="comment">root</span> <span class="comment">374872</span> <span class="comment">10月</span> <span class="comment">28</span> <span class="comment">14:18</span> <span class="comment">/usr/bin/fdfs_trackerd</span>
<span class="literal">-</span><span class="comment">rwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span> <span class="comment">1</span> <span class="comment">root</span> <span class="comment">root</span> <span class="comment">248730</span> <span class="comment">10月</span> <span class="comment">28</span> <span class="comment">14:18</span> <span class="comment">/usr/bin/fdfs_upload_appender</span>
<span class="literal">-</span><span class="comment">rwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span> <span class="comment">1</span> <span class="comment">root</span> <span class="comment">root</span> <span class="comment">249676</span> <span class="comment">10月</span> <span class="comment">28</span> <span class="comment">14:18</span> <span class="comment">/usr/bin/fdfs_upload_file</span>
<span class="title">[</span><span class="comment">root@server1</span> <span class="comment">FastDFS</span><span class="title">]</span><span class="comment">#</span> 
</code></pre>

<p>配置文件在 /etc/fdfs 目录下</p>

<pre><code class="brainfuck">
<span class="title">[</span><span class="comment">root@server1</span> <span class="comment">FastDFS</span><span class="title">]</span><span class="comment">#</span> <span class="comment">ll</span> <span class="comment">/etc/fdfs/</span>
<span class="comment">总用量</span> <span class="comment">20</span>
<span class="literal">-</span><span class="comment">rw</span><span class="literal">-</span><span class="comment">r</span><span class="literal">-</span><span class="literal">-</span><span class="comment">r</span><span class="literal">-</span><span class="literal">-</span> <span class="comment">1</span> <span class="comment">root</span> <span class="comment">root</span> <span class="comment">1461</span> <span class="comment">10月</span> <span class="comment">28</span> <span class="comment">14:18</span> <span class="comment">client</span><span class="string">.</span><span class="comment">conf</span><span class="string">.</span><span class="comment">sample</span>
<span class="literal">-</span><span class="comment">rw</span><span class="literal">-</span><span class="comment">r</span><span class="literal">-</span><span class="literal">-</span><span class="comment">r</span><span class="literal">-</span><span class="literal">-</span> <span class="comment">1</span> <span class="comment">root</span> <span class="comment">root</span> <span class="comment">7647</span> <span class="comment">10月</span> <span class="comment">28</span> <span class="comment">14:18</span> <span class="comment">storage</span><span class="string">.</span><span class="comment">conf</span><span class="string">.</span><span class="comment">sample</span>
<span class="literal">-</span><span class="comment">rw</span><span class="literal">-</span><span class="comment">r</span><span class="literal">-</span><span class="literal">-</span><span class="comment">r</span><span class="literal">-</span><span class="literal">-</span> <span class="comment">1</span> <span class="comment">root</span> <span class="comment">root</span> <span class="comment">7102</span> <span class="comment">10月</span> <span class="comment">28</span> <span class="comment">14:18</span> <span class="comment">tracker</span><span class="string">.</span><span class="comment">conf</span><span class="string">.</span><span class="comment">sample</span>
<span class="title">[</span><span class="comment">root@server1</span> <span class="comment">FastDFS</span><span class="title">]</span><span class="comment">#</span> 
</code></pre>

<h4>2.配置</h4>

<p>进入到 /etc/fdfs 目录下，复制/usr/local/src/FastDFS/conf/* 下面的所有文件到当前目录下(/etc/fdfs)</p>

<pre><code class="brainfuck">
<span class="title">[</span><span class="comment">root@server1</span> <span class="comment">FastDFS</span><span class="title">]</span><span class="comment">#</span> <span class="comment">cd</span> <span class="comment">/etc/fdfs/</span>
<span class="title">[</span><span class="comment">root@server1</span> <span class="comment">fdfs</span><span class="title">]</span><span class="comment">#</span> <span class="comment">cp</span> <span class="comment">/usr/local/src/FastDFS/conf/*</span> <span class="string">.</span>
<span class="title">[</span><span class="comment">root@server1</span> <span class="comment">fdfs</span><span class="title">]</span><span class="comment">#</span> <span class="comment">ll</span>
<span class="comment">总用量</span> <span class="comment">64</span>
<span class="literal">-</span><span class="comment">rw</span><span class="literal">-</span><span class="comment">r</span><span class="literal">-</span><span class="literal">-</span><span class="comment">r</span><span class="literal">-</span><span class="literal">-</span> <span class="comment">1</span> <span class="comment">root</span> <span class="comment">root</span>  <span class="comment">1461</span> <span class="comment">10月</span> <span class="comment">29</span> <span class="comment">14:33</span> <span class="comment">client</span><span class="string">.</span><span class="comment">conf</span>
<span class="literal">-</span><span class="comment">rw</span><span class="literal">-</span><span class="comment">r</span><span class="literal">-</span><span class="literal">-</span><span class="comment">r</span><span class="literal">-</span><span class="literal">-</span> <span class="comment">1</span> <span class="comment">root</span> <span class="comment">root</span>   <span class="comment">858</span> <span class="comment">10月</span> <span class="comment">29</span> <span class="comment">14:33</span> <span class="comment">http</span><span class="string">.</span><span class="comment">conf</span>
<span class="literal">-</span><span class="comment">rw</span><span class="literal">-</span><span class="comment">r</span><span class="literal">-</span><span class="literal">-</span><span class="comment">r</span><span class="literal">-</span><span class="literal">-</span> <span class="comment">1</span> <span class="comment">root</span> <span class="comment">root</span> <span class="comment">31172</span> <span class="comment">10月</span> <span class="comment">29</span> <span class="comment">14:33</span> <span class="comment">mime</span><span class="string">.</span><span class="comment">types</span>
<span class="literal">-</span><span class="comment">rw</span><span class="literal">-</span><span class="comment">r</span><span class="literal">-</span><span class="literal">-</span><span class="comment">r</span><span class="literal">-</span><span class="literal">-</span> <span class="comment">1</span> <span class="comment">root</span> <span class="comment">root</span>  <span class="comment">3697</span> <span class="comment">10月</span> <span class="comment">29</span> <span class="comment">14:34</span> <span class="comment">mod_fastdfs</span><span class="string">.</span><span class="comment">conf</span>
<span class="literal">-</span><span class="comment">rw</span><span class="literal">-</span><span class="comment">r</span><span class="literal">-</span><span class="literal">-</span><span class="comment">r</span><span class="literal">-</span><span class="literal">-</span> <span class="comment">1</span> <span class="comment">root</span> <span class="comment">root</span>  <span class="comment">7646</span> <span class="comment">10月</span> <span class="comment">28</span> <span class="comment">14:34</span> <span class="comment">storage</span><span class="string">.</span><span class="comment">conf</span>
<span class="literal">-</span><span class="comment">rw</span><span class="literal">-</span><span class="comment">r</span><span class="literal">-</span><span class="literal">-</span><span class="comment">r</span><span class="literal">-</span><span class="literal">-</span> <span class="comment">1</span> <span class="comment">root</span> <span class="comment">root</span>   <span class="comment">105</span> <span class="comment">10月</span> <span class="comment">29</span> <span class="comment">14:33</span> <span class="comment">storage_ids</span><span class="string">.</span><span class="comment">conf</span>
<span class="literal">-</span><span class="comment">rw</span><span class="literal">-</span><span class="comment">r</span><span class="literal">-</span><span class="literal">-</span><span class="comment">r</span><span class="literal">-</span><span class="literal">-</span> <span class="comment">1</span> <span class="comment">root</span> <span class="comment">root</span>  <span class="comment">7102</span> <span class="comment">10月</span> <span class="comment">29</span> <span class="comment">14:33</span> <span class="comment">tracker</span><span class="string">.</span><span class="comment">conf</span>
<span class="title">[</span><span class="comment">root@server1</span> <span class="comment">fdfs</span><span class="title">]</span><span class="comment">#</span> 
</code></pre>

<p>编辑配置文件 storage.conf 测试的时候，只需修改以下内容即可</p>

<pre><code class="coffeescript">
[root<span class="property">@server1</span> fdfs]<span class="comment"># vim storage.conf</span>
disabled=<span class="literal">false</span>                        <span class="comment">#启用配置文件</span>
group_name=group1                     <span class="comment">#组名，根据实际情况修改</span>
port=<span class="number">23000</span>                            <span class="comment">#设置 storage 的端口号</span>
base_path=/data/fastdfs/storage       <span class="comment">#设置 storage 的日志目录（需预先创建）</span>
store_path_count=<span class="number">1</span>                    <span class="comment">#存储路径个数，需要和 store_path 个数匹配</span>
store_path0=/data/fastdfs/storage     <span class="comment">#存储路径</span>
tracker_server=<span class="number">10.10</span><span class="number">.10</span><span class="number">.124</span>:<span class="number">22122</span>     <span class="comment">#tracker 服务器的 IP 地址和端口号</span>
http.server_port=<span class="number">8080</span>                 <span class="comment">#设置storage上启动的http服务的端口号，如安装的nginx的端口号</span>
</code></pre>

<h4>3.运行</h4>

<pre><code class="ruby">
[root<span class="variable">@server1</span> fdfs]<span class="comment"># fdfs_storaged /etc/fdfs/storage.conf restart</span>
</code></pre>

<p>查看端口是否起来</p>

<pre><code class="ruby">
[root<span class="variable">@server1</span> fdfs]<span class="comment"># netstat -antp | grep storage</span>
tcp        <span class="number">0</span>      <span class="number">0</span> <span class="number">0</span>.<span class="number">0</span>.<span class="number">0</span>.<span class="number">0</span><span class="symbol">:</span><span class="number">23000</span>               <span class="number">0</span>.<span class="number">0</span>.<span class="number">0</span>.<span class="number">0</span><span class="symbol">:*</span>                   <span class="constant">LISTEN</span>      <span class="number">10316</span>/fdfs_storaged 
[root<span class="variable">@server1</span> fdfs]<span class="comment"># </span>
</code></pre>

<p>观察日志 /data/fastdfs/storage/logs/storaged.log 看运行情况</p>

<pre><code class="r">
mkdir data path: FB <span class="keyword">...</span>
mkdir data path: FC <span class="keyword">...</span>
mkdir data path: FD <span class="keyword">...</span>
mkdir data path: FE <span class="keyword">...</span>
mkdir data path: FF <span class="keyword">...</span>
data path: /data/fastdfs/storage/data, mkdir sub dir done.
[<span class="number">2014</span>-<span class="number">10</span>-<span class="number">28</span> <span class="number">14</span>:<span class="number">42</span>:<span class="number">55</span>] INFO - file: storage_param_getter.c, line: <span class="number">191</span>, use_storage_id=<span class="number">0</span>, id_type_in_filename=ip, storage_ip_changed_auto_adjust=<span class="number">1</span>, store_path=<span class="number">0</span>, reserved_storage_space=<span class="number">10.00</span>%, use_trunk_file=<span class="number">0</span>, slot_min_size=<span class="number">256</span>, slot_max_size=<span class="number">16</span> MB, trunk_file_size=<span class="number">64</span> MB, trunk_create_file_advance=<span class="number">0</span>, trunk_create_file_time_base=<span class="number">02</span>:<span class="number">00</span>, trunk_create_file_interval=<span class="number">86400</span>, trunk_create_file_space_threshold=<span class="number">20</span> GB, trunk_init_check_occupying=<span class="number">0</span>, trunk_init_reload_from_binlog=<span class="number">0</span>, trunk_compress_binlog_min_interval=<span class="number">0</span>, store_slave_file_use_link=<span class="number">0</span>
[<span class="number">2014</span>-<span class="number">10</span>-<span class="number">28</span> <span class="number">14</span>:<span class="number">42</span>:<span class="number">55</span>] INFO - file: storage_func.c, line: <span class="number">175</span>, tracker_client_ip: <span class="number">10.10</span><span class="number">.10</span><span class="number">.120</span>, my_server_id_str: <span class="number">10.10</span><span class="number">.10</span><span class="number">.120</span>, g_server_id_in_filename: <span class="number">2013923850</span>
[<span class="number">2014</span>-<span class="number">10</span>-<span class="number">28</span> <span class="number">14</span>:<span class="number">42</span>:<span class="number">55</span>] INFO - local_host_ip_count: <span class="number">2</span>,  <span class="number">127.0</span><span class="number">.0</span><span class="number">.1</span>  <span class="number">10.10</span><span class="number">.10</span><span class="number">.120</span>
[<span class="number">2014</span>-<span class="number">10</span>-<span class="number">28</span> <span class="number">14</span>:<span class="number">42</span>:<span class="number">55</span>] INFO - file: tracker_client_thread.c, line: <span class="number">310</span>, successfully connect to tracker server <span class="number">10.10</span><span class="number">.10</span><span class="number">.124</span>:<span class="number">22122</span>, as a tracker client, my ip is <span class="number">10.10</span><span class="number">.10</span><span class="number">.120</span>
[<span class="number">2014</span>-<span class="number">10</span>-<span class="number">28</span> <span class="number">14</span>:<span class="number">43</span>:<span class="number">25</span>] INFO - file: tracker_client_thread.c, line: <span class="number">1235</span>, tracker server <span class="number">10.10</span><span class="number">.10</span><span class="number">.124</span>:<span class="number">22122</span>, set tracker leader: <span class="number">10.10</span><span class="number">.10</span><span class="number">.124</span>:<span class="number">22122</span>
</code></pre>

<p>看到先创建二级目录，然后已经成功连接到tracker</p>

<p>可以使用 fdfs_monitor 来查看一下storage的状态，看是否已经成功注册到了tracker</p>

<pre><code class="ruby">
[root<span class="variable">@server2</span> logs]<span class="comment"># fdfs_monitor /etc/fdfs/storage.conf</span>
</code></pre>

<p>也可以以下命令来监控服务器的状态</p>

<pre><code class="ruby">
[root<span class="variable">@tracker</span> ~]<span class="comment"># fdfs_monitor /etc/fdfs/client.conf</span>
</code></pre>

<p>结果如下:</p>

<pre><code class="brainfuck">
<span class="title">[</span><span class="comment">2014</span><span class="literal">-</span><span class="comment">10</span><span class="literal">-</span><span class="comment">28</span> <span class="comment">15:57:54</span><span class="title">]</span> <span class="comment">DEBUG</span> <span class="literal">-</span> <span class="comment">base_path=/data/fastdfs/storage</span><span class="string">,</span> <span class="comment">connect_timeout=30</span><span class="string">,</span> <span class="comment">network_timeout=60</span><span class="string">,</span> <span class="comment">tracker_server_count=1</span><span class="string">,</span> <span class="comment">anti_steal_token=0</span><span class="string">,</span> <span class="comment">anti_steal_secret_key</span> <span class="comment">length=0</span><span class="string">,</span> <span class="comment">use_connection_pool=0</span><span class="string">,</span> <span class="comment">g_connection_pool_max_idle_time=3600s</span><span class="string">,</span> <span class="comment">use_storage_id=0</span><span class="string">,</span> <span class="comment">storage</span> <span class="comment">server</span> <span class="comment">id</span> <span class="comment">count:</span> <span class="comment">0</span>
<span class="comment">server_count=1</span><span class="string">,</span> <span class="comment">server_index=0</span>
<span class="comment">tracker</span> <span class="comment">server</span> <span class="comment">is</span> <span class="comment">10</span><span class="string">.</span><span class="comment">10</span><span class="string">.</span><span class="comment">10</span><span class="string">.</span><span class="comment">124:22122</span>
<span class="comment">group</span> <span class="comment">count:</span> <span class="comment">1</span>
<span class="comment">Group</span> <span class="comment">1:</span>
<span class="comment">group</span> <span class="comment">name</span> <span class="comment">=</span> <span class="comment">group1</span>
<span class="comment">disk</span> <span class="comment">total</span> <span class="comment">space</span> <span class="comment">=</span> <span class="comment">14020</span> <span class="comment">MB</span>
<span class="comment">disk</span> <span class="comment">free</span> <span class="comment">space</span> <span class="comment">=</span> <span class="comment">10267</span> <span class="comment">MB</span>
<span class="comment">trunk</span> <span class="comment">free</span> <span class="comment">space</span> <span class="comment">=</span> <span class="comment">0</span> <span class="comment">MB</span>
<span class="comment">storage</span> <span class="comment">server</span> <span class="comment">count</span> <span class="comment">=</span> <span class="comment">2</span>
<span class="comment">active</span> <span class="comment">server</span> <span class="comment">count</span> <span class="comment">=</span> <span class="comment">2</span>
<span class="comment">storage</span> <span class="comment">server</span> <span class="comment">port</span> <span class="comment">=</span> <span class="comment">23000</span>
<span class="comment">storage</span> <span class="comment">HTTP</span> <span class="comment">port</span> <span class="comment">=</span> <span class="comment">8080</span>
<span class="comment">store</span> <span class="comment">path</span> <span class="comment">count</span> <span class="comment">=</span> <span class="comment">1</span>
<span class="comment">subdir</span> <span class="comment">count</span> <span class="comment">per</span> <span class="comment">path</span> <span class="comment">=</span> <span class="comment">256</span>
<span class="comment">current</span> <span class="comment">write</span> <span class="comment">server</span> <span class="comment">index</span> <span class="comment">=</span> <span class="comment">0</span>
<span class="comment">current</span> <span class="comment">trunk</span> <span class="comment">file</span> <span class="comment">id</span> <span class="comment">=</span> <span class="comment">0</span>
        <span class="comment">Storage</span> <span class="comment">1:</span>
                <span class="comment">id</span> <span class="comment">=</span> <span class="comment">10</span><span class="string">.</span><span class="comment">10</span><span class="string">.</span><span class="comment">10</span><span class="string">.</span><span class="comment">120</span>
                <span class="comment">ip_addr</span> <span class="comment">=</span> <span class="comment">10</span><span class="string">.</span><span class="comment">10</span><span class="string">.</span><span class="comment">10</span><span class="string">.</span><span class="comment">120</span>  <span class="comment">ACTIVE</span>
                <span class="comment">http</span> <span class="comment">domain</span> <span class="comment">=</span> 
                <span class="comment">version</span> <span class="comment">=</span> <span class="comment">5</span><span class="string">.</span><span class="comment">04</span>
                <span class="comment">join</span> <span class="comment">time</span> <span class="comment">=</span> <span class="comment">2014</span><span class="literal">-</span><span class="comment">10</span><span class="literal">-</span><span class="comment">28</span> <span class="comment">14:42:43</span>
                <span class="comment">up</span> <span class="comment">time</span> <span class="comment">=</span> <span class="comment">2014</span><span class="literal">-</span><span class="comment">10</span><span class="literal">-</span><span class="comment">28</span> <span class="comment">14:42:43</span>
                <span class="comment">total</span> <span class="comment">storage</span> <span class="comment">=</span> <span class="comment">14020</span> <span class="comment">MB</span>
                <span class="comment">free</span> <span class="comment">storage</span> <span class="comment">=</span> <span class="comment">10385</span> <span class="comment">MB</span>
                <span class="comment">upload</span> <span class="comment">priority</span> <span class="comment">=</span> <span class="comment">10</span>
                <span class="comment">store_path_count</span> <span class="comment">=</span> <span class="comment">1</span>
                <span class="comment">subdir_count_per_path</span> <span class="comment">=</span> <span class="comment">256</span>
                <span class="comment">storage_port</span> <span class="comment">=</span> <span class="comment">23000</span>
                <span class="comment">storage_http_port</span> <span class="comment">=</span> <span class="comment">8080</span>
                <span class="comment">current_write_path</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">source</span> <span class="comment">storage</span> <span class="comment">id</span> <span class="comment">=</span> 
                <span class="comment">if_trunk_server</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">connection</span><span class="string">.</span><span class="comment">alloc_count</span> <span class="comment">=</span> <span class="comment">256</span>
                <span class="comment">connection</span><span class="string">.</span><span class="comment">current_count</span> <span class="comment">=</span> <span class="comment">1</span>
                <span class="comment">connection</span><span class="string">.</span><span class="comment">max_count</span> <span class="comment">=</span> <span class="comment">1</span>
                <span class="comment">total_upload_count</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">success_upload_count</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">total_append_count</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">success_append_count</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">total_modify_count</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">success_modify_count</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">total_truncate_count</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">success_truncate_count</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">total_set_meta_count</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">success_set_meta_count</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">total_delete_count</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">success_delete_count</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">total_download_count</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">success_download_count</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">total_get_meta_count</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">success_get_meta_count</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">total_create_link_count</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">success_create_link_count</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">total_delete_link_count</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">success_delete_link_count</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">total_upload_bytes</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">success_upload_bytes</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">total_append_bytes</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">success_append_bytes</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">total_modify_bytes</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">success_modify_bytes</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">stotal_download_bytes</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">success_download_bytes</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">total_sync_in_bytes</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">success_sync_in_bytes</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">total_sync_out_bytes</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">success_sync_out_bytes</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">total_file_open_count</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">success_file_open_count</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">total_file_read_count</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">success_file_read_count</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">total_file_write_count</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">success_file_write_count</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">last_heart_beat_time</span> <span class="comment">=</span> <span class="comment">2014</span><span class="literal">-</span><span class="comment">10</span><span class="literal">-</span><span class="comment">28</span> <span class="comment">15:56:42</span>
                <span class="comment">last_source_update</span> <span class="comment">=</span> <span class="comment">1970</span><span class="literal">-</span><span class="comment">01</span><span class="literal">-</span><span class="comment">01</span> <span class="comment">08:00:00</span>
                <span class="comment">last_sync_update</span> <span class="comment">=</span> <span class="comment">1970</span><span class="literal">-</span><span class="comment">01</span><span class="literal">-</span><span class="comment">01</span> <span class="comment">08:00:00</span>
                <span class="comment">last_synced_timestamp</span> <span class="comment">=</span> <span class="comment">1970</span><span class="literal">-</span><span class="comment">01</span><span class="literal">-</span><span class="comment">01</span> <span class="comment">08:00:00</span> 
        <span class="comment">Storage</span> <span class="comment">2:</span>
                <span class="comment">id</span> <span class="comment">=</span> <span class="comment">10</span><span class="string">.</span><span class="comment">10</span><span class="string">.</span><span class="comment">10</span><span class="string">.</span><span class="comment">122</span>
                <span class="comment">ip_addr</span> <span class="comment">=</span> <span class="comment">10</span><span class="string">.</span><span class="comment">10</span><span class="string">.</span><span class="comment">10</span><span class="string">.</span><span class="comment">122</span> <span class="comment">(shizhouliang</span><span class="string">.</span><span class="comment">mobimtech</span><span class="string">.</span><span class="comment">local)</span>  <span class="comment">ACTIVE</span>
                <span class="comment">http</span> <span class="comment">domain</span> <span class="comment">=</span> 
                <span class="comment">version</span> <span class="comment">=</span> <span class="comment">5</span><span class="string">.</span><span class="comment">04</span>
                <span class="comment">join</span> <span class="comment">time</span> <span class="comment">=</span> <span class="comment">2014</span><span class="literal">-</span><span class="comment">10</span><span class="literal">-</span><span class="comment">28</span> <span class="comment">15:53:51</span>
                <span class="comment">up</span> <span class="comment">time</span> <span class="comment">=</span> <span class="comment">2014</span><span class="literal">-</span><span class="comment">10</span><span class="literal">-</span><span class="comment">28</span> <span class="comment">15:53:51</span>
                <span class="comment">total</span> <span class="comment">storage</span> <span class="comment">=</span> <span class="comment">14020</span> <span class="comment">MB</span>
                <span class="comment">free</span> <span class="comment">storage</span> <span class="comment">=</span> <span class="comment">10267</span> <span class="comment">MB</span>
                <span class="comment">upload</span> <span class="comment">priority</span> <span class="comment">=</span> <span class="comment">10</span>
                <span class="comment">store_path_count</span> <span class="comment">=</span> <span class="comment">1</span>
                <span class="comment">subdir_count_per_path</span> <span class="comment">=</span> <span class="comment">256</span>
                <span class="comment">storage_port</span> <span class="comment">=</span> <span class="comment">23000</span>
                <span class="comment">storage_http_port</span> <span class="comment">=</span> <span class="comment">8080</span>
                <span class="comment">current_write_path</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">source</span> <span class="comment">storage</span> <span class="comment">id</span> <span class="comment">=</span> <span class="comment">10</span><span class="string">.</span><span class="comment">10</span><span class="string">.</span><span class="comment">10</span><span class="string">.</span><span class="comment">120</span>
                <span class="comment">if_trunk_server</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">connection</span><span class="string">.</span><span class="comment">alloc_count</span> <span class="comment">=</span> <span class="comment">256</span>
                <span class="comment">connection</span><span class="string">.</span><span class="comment">current_count</span> <span class="comment">=</span> <span class="comment">1</span>
                <span class="comment">connection</span><span class="string">.</span><span class="comment">max_count</span> <span class="comment">=</span> <span class="comment">1</span>
                <span class="comment">total_upload_count</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">success_upload_count</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">total_append_count</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">success_append_count</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">total_modify_count</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">success_modify_count</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">total_truncate_count</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">success_truncate_count</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">total_set_meta_count</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">success_set_meta_count</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">total_delete_count</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">success_delete_count</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">total_download_count</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">success_download_count</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">total_get_meta_count</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">success_get_meta_count</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">total_create_link_count</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">success_create_link_count</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">total_delete_link_count</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">success_delete_link_count</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">total_upload_bytes</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">success_upload_bytes</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">total_append_bytes</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">success_append_bytes</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">total_modify_bytes</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">success_modify_bytes</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">stotal_download_bytes</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">success_download_bytes</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">total_sync_in_bytes</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">success_sync_in_bytes</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">total_sync_out_bytes</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">success_sync_out_bytes</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">total_file_open_count</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">success_file_open_count</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">total_file_read_count</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">success_file_read_count</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">total_file_write_count</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">success_file_write_count</span> <span class="comment">=</span> <span class="comment">0</span>
                <span class="comment">last_heart_beat_time</span> <span class="comment">=</span> <span class="comment">2014</span><span class="literal">-</span><span class="comment">10</span><span class="literal">-</span><span class="comment">28</span> <span class="comment">15:56:53</span>
                <span class="comment">last_source_update</span> <span class="comment">=</span> <span class="comment">1970</span><span class="literal">-</span><span class="comment">01</span><span class="literal">-</span><span class="comment">01</span> <span class="comment">08:00:00</span>
                <span class="comment">last_sync_update</span> <span class="comment">=</span> <span class="comment">1970</span><span class="literal">-</span><span class="comment">01</span><span class="literal">-</span><span class="comment">01</span> <span class="comment">08:00:00</span>
                <span class="comment">last_synced_timestamp</span> <span class="comment">=</span> <span class="comment">1970</span><span class="literal">-</span><span class="comment">01</span><span class="literal">-</span><span class="comment">01</span> <span class="comment">08:00:00</span> 
</code></pre>

<p>看到ACTIVE,就说明已经成功注册到了tracker。</p>

<h4>4.设置开机启动</h4>

<pre><code class="bash">
[root@server1 fdfs]<span class="comment"># echo "/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart" &gt;&gt; /etc/rc.local</span>
[root@server1 fdfs]<span class="comment"># cat /etc/rc.local</span>
<span class="shebang">#!/bin/sh</span>
<span class="comment">#</span>
<span class="comment"># This script will be executed *after* all the other init scripts.</span>
<span class="comment"># You can put your own initialization stuff in here if you don't</span>
<span class="comment"># want to do the full Sys V style init stuff.</span>
touch /var/lock/subsys/local
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart
</code></pre>

<p>至此 storage 已经成功安装，再把另外一台服务器也同样的步骤进行安装。</p>

<p>等第二台storage2(10.10.10.122)安装完成并成功启动后，看日志会发现</p>

<pre><code class="brainfuck">
<span class="title">[</span><span class="comment">2014</span><span class="literal">-</span><span class="comment">10</span><span class="literal">-</span><span class="comment">28</span> <span class="comment">15:54:05</span><span class="title">]</span> <span class="comment">INFO</span> <span class="literal">-</span> <span class="comment">file:</span> <span class="comment">storage_sync</span><span class="string">.</span><span class="comment">c</span><span class="string">,</span> <span class="comment">line:</span> <span class="comment">2698</span><span class="string">,</span> <span class="comment">successfully</span> <span class="comment">connect</span> <span class="comment">to</span> <span class="comment">storage</span> <span class="comment">server</span> <span class="comment">10</span><span class="string">.</span><span class="comment">10</span><span class="string">.</span><span class="comment">10</span><span class="string">.</span><span class="comment">120:23000</span>
</code></pre>

<p>说明已经成功连接到另外一台storage了。</p>

<p>也可以使用</p>

<pre><code class="ruby">
[root<span class="variable">@server2</span> logs]<span class="comment"># fdfs_monitor /etc/fdfs/storage.conf</span>
</code></pre>

<p>来查看一下storage2的状态</p>

<h1>四、在storage上安装配置nginx</h1>

<p>以下操作是在 storage1 10.10.10.120 上操作</p>

<h4>1.安装nginx</h4>

<p>上传 fastdfs-nginx-module_v1.16.tar.gz nginx-1.4.7.tar.gz pcre-8.36.tar.gz zlib-1.2.8.tar.gz 到storage服务器上的/usr/local/src 目录下</p>

<pre><code class="avrasm">
[root@server1 src]<span class="preprocessor"># rz</span>
rz waiting to receive.
Starting zmodem transfer.  Press Ctrl+C to cancel.
Transferring fastdfs-nginx-module_v1<span class="number">.16</span><span class="preprocessor">.tar</span><span class="preprocessor">.gz</span>...
  <span class="number">100</span>%      <span class="number">17</span> KB      <span class="number">17</span> KB/<span class="keyword">sec</span>    <span class="number">00</span>:<span class="number">00</span>:<span class="number">01</span>       <span class="number">0</span> Errors  
Transferring nginx-<span class="number">1.4</span><span class="number">.7</span><span class="preprocessor">.tar</span><span class="preprocessor">.gz</span>...
  <span class="number">100</span>%     <span class="number">751</span> KB     <span class="number">751</span> KB/<span class="keyword">sec</span>    <span class="number">00</span>:<span class="number">00</span>:<span class="number">01</span>       <span class="number">0</span> Errors  
Transferring pcre-<span class="number">8.36</span><span class="preprocessor">.tar</span><span class="preprocessor">.gz</span>...
  <span class="number">100</span>%    <span class="number">1962</span> KB    <span class="number">1962</span> KB/<span class="keyword">sec</span>    <span class="number">00</span>:<span class="number">00</span>:<span class="number">01</span>       <span class="number">0</span> Errors  
Transferring zlib-<span class="number">1.2</span><span class="number">.8</span><span class="preprocessor">.tar</span><span class="preprocessor">.gz</span>...
  <span class="number">100</span>%     <span class="number">557</span> KB     <span class="number">557</span> KB/<span class="keyword">sec</span>    <span class="number">00</span>:<span class="number">00</span>:<span class="number">01</span>       <span class="number">0</span> Errors  
</code></pre>

<p>解压各个文件，然后编译安装nginx</p>

<pre><code class="brainfuck">
<span class="title">[</span><span class="comment">root@server1</span> <span class="comment">src</span><span class="title">]</span><span class="comment">#</span> <span class="comment">tar</span> <span class="comment">xf</span> <span class="comment">nginx</span><span class="literal">-</span><span class="comment">1</span><span class="string">.</span><span class="comment">4</span><span class="string">.</span><span class="comment">7</span><span class="string">.</span><span class="comment">tar</span><span class="string">.</span><span class="comment">gz</span> 
<span class="title">[</span><span class="comment">root@server1</span> <span class="comment">src</span><span class="title">]</span><span class="comment">#</span> <span class="comment">tar</span> <span class="comment">xf</span> <span class="comment">pcre</span><span class="literal">-</span><span class="comment">8</span><span class="string">.</span><span class="comment">36</span><span class="string">.</span><span class="comment">tar</span><span class="string">.</span><span class="comment">gz</span> 
<span class="title">[</span><span class="comment">root@server1</span> <span class="comment">src</span><span class="title">]</span><span class="comment">#</span> <span class="comment">tar</span> <span class="comment">xf</span> <span class="comment">zlib</span><span class="literal">-</span><span class="comment">1</span><span class="string">.</span><span class="comment">2</span><span class="string">.</span><span class="comment">8</span><span class="string">.</span><span class="comment">tar</span><span class="string">.</span><span class="comment">gz</span> 
<span class="title">[</span><span class="comment">root@server1</span> <span class="comment">src</span><span class="title">]</span><span class="comment">#</span> <span class="comment">tar</span> <span class="comment">xf</span> <span class="comment">fastdfs</span><span class="literal">-</span><span class="comment">nginx</span><span class="literal">-</span><span class="comment">module_v1</span><span class="string">.</span><span class="comment">16</span><span class="string">.</span><span class="comment">tar</span><span class="string">.</span><span class="comment">gz</span> 
<span class="title">[</span><span class="comment">root@server1</span> <span class="comment">src</span><span class="title">]</span><span class="comment">#</span> <span class="comment">cd</span> <span class="comment">nginx</span><span class="literal">-</span><span class="comment">1</span><span class="string">.</span><span class="comment">4</span><span class="string">.</span><span class="comment">7</span>
<span class="title">[</span><span class="comment">root@server1</span> <span class="comment">nginx</span><span class="literal">-</span><span class="comment">1</span><span class="string">.</span><span class="comment">4</span><span class="string">.</span><span class="comment">7</span><span class="title">]</span><span class="comment">#</span> <span class="comment">ls</span>
<span class="comment">auto</span>  <span class="comment">CHANGES</span>  <span class="comment">CHANGES</span><span class="string">.</span><span class="comment">ru</span>  <span class="comment">conf</span>  <span class="comment">configure</span>  <span class="comment">contrib</span>  <span class="comment">html</span>  <span class="comment">LICENSE</span>  <span class="comment">man</span>  <span class="comment">README</span>  <span class="comment">src</span>
<span class="title">[</span><span class="comment">root@server1</span> <span class="comment">nginx</span><span class="literal">-</span><span class="comment">1</span><span class="string">.</span><span class="comment">4</span><span class="string">.</span><span class="comment">7</span><span class="title">]</span><span class="comment">#</span> <span class="string">.</span><span class="comment">/configure</span> <span class="literal">-</span><span class="literal">-</span><span class="comment">prefix=/usr/local/nginx</span> <span class="literal">-</span><span class="literal">-</span><span class="comment">add</span><span class="literal">-</span><span class="comment">module=/usr/local/src/fastdfs</span><span class="literal">-</span><span class="comment">nginx</span><span class="literal">-</span><span class="comment">module/src</span> <span class="literal">-</span><span class="literal">-</span><span class="comment">with</span><span class="literal">-</span><span class="comment">pcre=/usr/local/src/pcre</span><span class="literal">-</span><span class="comment">8</span><span class="string">.</span><span class="comment">36</span> <span class="literal">-</span><span class="literal">-</span><span class="comment">with</span><span class="literal">-</span><span class="comment">zlib=/usr/local/src/zlib</span><span class="literal">-</span><span class="comment">1</span><span class="string">.</span><span class="comment">2</span><span class="string">.</span><span class="comment">8</span>
</code></pre>

<p>出现以下错误:</p>

<pre><code class="lasso">
cc <span class="attribute">-c</span> <span class="attribute">-pipe</span>  <span class="attribute">-O</span> <span class="attribute">-W</span> <span class="attribute">-Wall</span> <span class="attribute">-Wpointer</span><span class="attribute">-arith</span> <span class="attribute">-Wno</span><span class="attribute">-unused</span><span class="attribute">-parameter</span> <span class="attribute">-Werror</span> <span class="attribute">-g</span>  <span class="attribute">-D_FILE_OFFSET_BITS</span><span class="subst">=</span><span class="number">64</span> <span class="attribute">-DFDFS_OUTPUT_CHUNK_SIZE</span><span class="subst">=</span><span class="string">'256*1024'</span> <span class="attribute">-DFDFS_MOD_CONF_FILENAME</span><span class="subst">=</span><span class="string">'"/etc/fdfs/mod_fastdfs.conf"'</span>  <span class="attribute">-I</span> src<span class="subst">/</span>core <span class="attribute">-I</span> src<span class="subst">/</span>event <span class="attribute">-I</span> src<span class="subst">/</span>event<span class="subst">/</span>modules <span class="attribute">-I</span> src<span class="subst">/</span>os<span class="subst">/</span>unix <span class="attribute">-I</span> <span class="subst">/</span>usr<span class="subst">/</span><span class="built_in">local</span><span class="subst">/</span>include<span class="subst">/</span>fastdfs <span class="attribute">-I</span> <span class="subst">/</span>usr<span class="subst">/</span><span class="built_in">local</span><span class="subst">/</span>include<span class="subst">/</span>fastcommon<span class="subst">/</span> <span class="attribute">-I</span> <span class="subst">/</span>usr<span class="subst">/</span><span class="built_in">local</span><span class="subst">/</span>src<span class="subst">/</span>pcre<span class="subst">-</span><span class="number">8.36</span> <span class="attribute">-I</span> <span class="subst">/</span>usr<span class="subst">/</span><span class="built_in">local</span><span class="subst">/</span>src<span class="subst">/</span>zlib<span class="subst">-</span><span class="number">1.2</span><span class="number">.8</span> <span class="attribute">-I</span> objs <span class="attribute">-I</span> src<span class="subst">/</span>http <span class="attribute">-I</span> src<span class="subst">/</span>http<span class="subst">/</span>modules <span class="attribute">-I</span> src<span class="subst">/</span>mail <span class="subst">\</span>
                <span class="attribute">-o</span> objs<span class="subst">/</span>addon<span class="subst">/</span>src<span class="subst">/</span>ngx_http_fastdfs_module<span class="built_in">.</span>o <span class="subst">\</span>
                <span class="subst">/</span>usr<span class="subst">/</span><span class="built_in">local</span><span class="subst">/</span>src<span class="subst">/</span>fastdfs<span class="attribute">-nginx</span><span class="attribute">-module</span><span class="subst">/</span>src<span class="subst">/</span>ngx_http_fastdfs_module<span class="built_in">.</span>c
在包含自 <span class="subst">/</span>usr<span class="subst">/</span><span class="built_in">local</span><span class="subst">/</span>src<span class="subst">/</span>fastdfs<span class="attribute">-nginx</span><span class="attribute">-module</span><span class="subst">/</span>src<span class="subst">/</span>ngx_http_fastdfs_module<span class="built_in">.</span>c：<span class="number">6</span> 的文件中:
<span class="subst">/</span>usr<span class="subst">/</span><span class="built_in">local</span><span class="subst">/</span>src<span class="subst">/</span>fastdfs<span class="attribute">-nginx</span><span class="attribute">-module</span><span class="subst">/</span>src<span class="subst">/</span>common<span class="built_in">.</span>c:<span class="number">21</span>:<span class="number">25</span>: 错误：fdfs_define<span class="built_in">.</span>h：没有那个文件或目录
<span class="subst">/</span>usr<span class="subst">/</span><span class="built_in">local</span><span class="subst">/</span>src<span class="subst">/</span>fastdfs<span class="attribute">-nginx</span><span class="attribute">-module</span><span class="subst">/</span>src<span class="subst">/</span>common<span class="built_in">.</span>c:<span class="number">22</span>:<span class="number">20</span>: 错误：logger<span class="built_in">.</span>h：没有那个文件或目录
<span class="subst">/</span>usr<span class="subst">/</span><span class="built_in">local</span><span class="subst">/</span>src<span class="subst">/</span>fastdfs<span class="attribute">-nginx</span><span class="attribute">-module</span><span class="subst">/</span>src<span class="subst">/</span>common<span class="built_in">.</span>c:<span class="number">23</span>:<span class="number">25</span>: 错误：shared_func<span class="built_in">.</span>h：没有那个文件或目录
<span class="subst">/</span>usr<span class="subst">/</span><span class="built_in">local</span><span class="subst">/</span>src<span class="subst">/</span>fastdfs<span class="attribute">-nginx</span><span class="attribute">-module</span><span class="subst">/</span>src<span class="subst">/</span>common<span class="built_in">.</span>c:<span class="number">24</span>:<span class="number">25</span>: 错误：fdfs_global<span class="built_in">.</span>h：没有那个文件或目录
<span class="subst">/</span>usr<span class="subst">/</span><span class="built_in">local</span><span class="subst">/</span>src<span class="subst">/</span>fastdfs<span class="attribute">-nginx</span><span class="attribute">-module</span><span class="subst">/</span>src<span class="subst">/</span>common<span class="built_in">.</span>c:<span class="number">25</span>:<span class="number">21</span>: 错误：sockopt<span class="built_in">.</span>h：没有那个文件或目录
<span class="subst">/</span>usr<span class="subst">/</span><span class="built_in">local</span><span class="subst">/</span>src<span class="subst">/</span>fastdfs<span class="attribute">-nginx</span><span class="attribute">-module</span><span class="subst">/</span>src<span class="subst">/</span>common<span class="built_in">.</span>c:<span class="number">26</span>:<span class="number">23</span>: 错误：http_func<span class="built_in">.</span>h：没有那个文件或目录
<span class="subst">/</span>usr<span class="subst">/</span><span class="built_in">local</span><span class="subst">/</span>src<span class="subst">/</span>fastdfs<span class="attribute">-nginx</span><span class="attribute">-module</span><span class="subst">/</span>src<span class="subst">/</span>common<span class="built_in">.</span>c:<span class="number">27</span>:<span class="number">30</span>: 错误：fdfs_http_shared<span class="built_in">.</span>h：没有那个文件或目录
<span class="subst">/</span>usr<span class="subst">/</span><span class="built_in">local</span><span class="subst">/</span>src<span class="subst">/</span>fastdfs<span class="attribute">-nginx</span><span class="attribute">-module</span><span class="subst">/</span>src<span class="subst">/</span>common<span class="built_in">.</span>c:<span class="number">28</span>:<span class="number">25</span>: 错误：fdfs_client<span class="built_in">.</span>h：没有那个文件或目录
<span class="subst">/</span>usr<span class="subst">/</span><span class="built_in">local</span><span class="subst">/</span>src<span class="subst">/</span>fastdfs<span class="attribute">-nginx</span><span class="attribute">-module</span><span class="subst">/</span>src<span class="subst">/</span>common<span class="built_in">.</span>c:<span class="number">29</span>:<span class="number">27</span>: 错误：local_ip_func<span class="built_in">.</span>h：没有那个文件或目录
<span class="subst">/</span>usr<span class="subst">/</span><span class="built_in">local</span><span class="subst">/</span>src<span class="subst">/</span>fastdfs<span class="attribute">-nginx</span><span class="attribute">-module</span><span class="subst">/</span>src<span class="subst">/</span>common<span class="built_in">.</span>c:<span class="number">30</span>:<span class="number">30</span>: 错误：fdfs_shared_func<span class="built_in">.</span>h：没有那个文件或目录
<span class="subst">/</span>usr<span class="subst">/</span><span class="built_in">local</span><span class="subst">/</span>src<span class="subst">/</span>fastdfs<span class="attribute">-nginx</span><span class="attribute">-module</span><span class="subst">/</span>src<span class="subst">/</span>common<span class="built_in">.</span>c:<span class="number">31</span>:<span class="number">26</span>: 错误：trunk_shared<span class="built_in">.</span>h：没有那个文件或目录
</code></pre>

<p>以上的这个错误是由于没找到 头文件导致的，找了找原因,在编译fastdf模块的时候会找这个地方/usr/local/include寻找fastdfs主程序的fastcommon和fastdfs这2个目录下的头文件，但是在编译安装的fastdfs主程序的时候，却把这2个目录放到了/usr/include下面了，于是复制这2个目录到/usr/local/include下</p>

<pre><code class="ruby">
[root<span class="variable">@server1</span> src]<span class="comment"># cp -rf /usr/include/fast* /usr/local/include/</span>
[root<span class="variable">@server1</span> src]<span class="comment"># ls /usr/local/include/</span>
fastcommon  fastdfs
[root<span class="variable">@server1</span> src]<span class="comment"># </span>
</code></pre>

<p>于是再次编译</p>

<pre><code class="brainfuck">
<span class="title">[</span><span class="comment">root@server1</span> <span class="comment">src</span><span class="title">]</span><span class="comment">#</span> <span class="comment">cd</span> <span class="comment">nginx</span><span class="literal">-</span><span class="comment">1</span><span class="string">.</span><span class="comment">4</span><span class="string">.</span><span class="comment">7</span>
<span class="title">[</span><span class="comment">root@server1</span> <span class="comment">nginx</span><span class="literal">-</span><span class="comment">1</span><span class="string">.</span><span class="comment">4</span><span class="string">.</span><span class="comment">7</span><span class="title">]</span><span class="comment">#</span> <span class="string">.</span><span class="comment">/configure</span> <span class="literal">-</span><span class="literal">-</span><span class="comment">prefix=/usr/local/nginx</span> <span class="literal">-</span><span class="literal">-</span><span class="comment">add</span><span class="literal">-</span><span class="comment">module=/usr/local/src/fastdfs</span><span class="literal">-</span><span class="comment">nginx</span><span class="literal">-</span><span class="comment">module/src</span> <span class="literal">-</span><span class="literal">-</span><span class="comment">with</span><span class="literal">-</span><span class="comment">pcre=/usr/local/src/pcre</span><span class="literal">-</span><span class="comment">8</span><span class="string">.</span><span class="comment">36</span> <span class="literal">-</span><span class="literal">-</span><span class="comment">with</span><span class="literal">-</span><span class="comment">zlib=/usr/local/src/zlib</span><span class="literal">-</span><span class="comment">1</span><span class="string">.</span><span class="comment">2</span><span class="string">.</span><span class="comment">8</span>
<span class="title">[</span><span class="comment">root@server1</span> <span class="comment">nginx</span><span class="literal">-</span><span class="comment">1</span><span class="string">.</span><span class="comment">4</span><span class="string">.</span><span class="comment">7</span><span class="title">]</span><span class="comment">#</span> <span class="comment">make</span> <span class="comment">&amp;&amp;</span> <span class="comment">make</span> <span class="comment">install</span> 
</code></pre>

<p>这次终于编译安装通过。</p>

<h4>2.准备启动脚本</h4>

<p>编辑 /etc/init.d/nginx，如下内容:</p>

<pre><code class="bash">
<span class="shebang">#!/bin/bash</span>
<span class="comment"># nginx Startup script for the Nginx HTTP Server</span>
<span class="comment"># it is v.1.4.7 version.</span>
<span class="comment"># chkconfig: - 85 15</span>
<span class="comment"># description: Nginx is a high-performance web and proxy server.</span>
<span class="comment"># It has a lot of features, but it's not for everyone.</span>
<span class="comment"># processname: nginx</span>
 
<span class="comment"># pidfile: /usr/local/nginx/logs/nginx.pid</span>
<span class="comment"># config: /usr/local/nginx/conf/nginx.conf</span>
 
nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/usr/local/nginx/logs/nginx.pid
nginx_lock=/var/lock/subsys/nginx
RETVAL=<span class="number">0</span>
prog=<span class="string">"nginx"</span>
 
<span class="comment"># Source function library.</span>
. /etc/rc.d/init.d/functions
 
<span class="comment"># Source networking configuration.</span>
. /etc/sysconfig/network
 
<span class="comment"># Check that networking is up.</span>
[ <span class="variable">${NETWORKING}</span> = <span class="string">"no"</span> ] &amp;&amp; <span class="keyword">exit</span> <span class="number">0</span>
[ -x <span class="variable">$nginxd</span> ] || <span class="keyword">exit</span> <span class="number">0</span>
 
<span class="comment"># Start nginx daemons functions.</span>
<span class="function"><span class="title">start</span></span>() {
    nginx_is_run=`ps -ef | egrep <span class="string">'nginx:\s*(worker|master)\s*process'</span> | wc <span class="operator">-l</span>`
    <span class="keyword">if</span> [ <span class="variable">${nginx_is_run}</span> <span class="operator">-gt</span> <span class="number">0</span> ];<span class="keyword">then</span>
        <span class="built_in">echo</span> <span class="string">"nginx already running...."</span>
        <span class="keyword">exit</span> <span class="number">1</span>
    <span class="keyword">fi</span>
    <span class="built_in">echo</span> -n $<span class="string">"Starting <span class="variable">$prog</span>: "</span>
    daemon <span class="variable">$nginxd</span> -c <span class="variable">${nginx_config}</span>
    RETVAL=$?
    <span class="built_in">echo</span>
    [ <span class="variable">$RETVAL</span> = <span class="number">0</span> ] &amp;&amp; touch <span class="variable">${nginx_lock}</span>
    <span class="keyword">return</span> <span class="variable">$RETVAL</span>
}
 
<span class="comment"># Stop nginx daemons functions.</span>
<span class="function"><span class="title">stop</span></span>() {
    <span class="built_in">echo</span> -n $<span class="string">"Stopping <span class="variable">$prog</span>: "</span>
    killproc <span class="variable">$nginxd</span>
    RETVAL=$?
    <span class="built_in">echo</span>
    [ <span class="variable">$RETVAL</span> = <span class="number">0</span> ] &amp;&amp; rm <span class="operator">-f</span> <span class="variable">${nginx_lock}</span> <span class="variable">${nginx_pid}</span>
}
 
<span class="comment"># Reload nginx config file</span>
<span class="function"><span class="title">reload</span></span>() {
    <span class="built_in">echo</span> -n $<span class="string">"Reloading <span class="variable">$prog</span>: "</span>
    <span class="comment">#kill -HUP `cat ${nginx_pid}`</span>
    killproc <span class="variable">$nginxd</span> -HUP
    RETVAL=$?
    <span class="built_in">echo</span>
}
 
<span class="comment"># See how we were called.</span>
<span class="keyword">case</span> <span class="string">"<span class="variable">$1</span>"</span> <span class="keyword">in</span>
    start)
        start
        ;;
    stop)
        stop
        ;;
    reload)
        reload
        ;;
    restart)
          stop
        start
        ;;
    status)
        status <span class="variable">$prog</span>
        RETVAL=$?
        ;;
    *)
        <span class="built_in">echo</span> $<span class="string">"Usage: <span class="variable">$prog</span> {start|stop|restart|reload|status|help}"</span>
        <span class="keyword">exit</span> <span class="number">1</span>
<span class="keyword">esac</span>
</code></pre>

<h4>3.将 FastDFS 的 nginx 插件模块的配置文件</h4>

<p>copy 到 FastDFS 配置文件目录</p>

<pre><code class="brainfuck">
<span class="title">[</span><span class="comment">root@server1</span> <span class="comment">src</span><span class="title">]</span><span class="comment">#</span> <span class="comment">cp</span> <span class="comment">fastdfs</span><span class="literal">-</span><span class="comment">nginx</span><span class="literal">-</span><span class="comment">module/src/mod_fastdfs</span><span class="string">.</span><span class="comment">conf</span> <span class="comment">/etc/fdfs/</span>
</code></pre>

<h4>4.修改nginx配置文件</h4>

<h5>① 修改nginx的监听端口</h5>

<p>将 server 段中的 listen 端口号改为 8080：</p>

<pre><code class="perl">
[root<span class="variable">@server1</span> nginx]<span class="comment"># vim /usr/local/nginx/conf/nginx.conf</span>
<span class="keyword">listen</span>       <span class="number">8080</span>;
</code></pre>

<h5>② 在 server 段中添加fastdfs的配置</h5>

<p>这里的group[1-3] 可以匹配 group1,group2,group3，当然group也可以是其他的名字</p>

<pre><code class="haskell">
<span class="title">location</span> ~ /group[<span class="number">1</span>-<span class="number">3</span>]/<span class="type">M00</span> {
            root /<span class="keyword">data</span>/fastdfs/storage/<span class="keyword">data</span>;
            ngx_fastdfs_module;
        }
</code></pre>

<p>/data/fastdfs/storage/data 这个是指向 真正存储文件的地方，该目录下有这些个二级目录</p>

<pre><code class="brainfuck">
<span class="title">[</span><span class="comment">root@server1</span> <span class="comment">src</span><span class="title">]</span><span class="comment">#</span> <span class="comment">cd</span> <span class="comment">/data/fastdfs/storage/data/</span>
<span class="title">[</span><span class="comment">root@server1</span> <span class="comment">data</span><span class="title">]</span><span class="comment">#</span> <span class="comment">ll</span>
<span class="comment">总用量</span> <span class="comment">1036</span>
<span class="comment">drwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span> <span class="comment">258</span> <span class="comment">root</span> <span class="comment">root</span> <span class="comment">4096</span> <span class="comment">10月</span> <span class="comment">28</span> <span class="comment">14:42</span> <span class="comment">00</span>
<span class="comment">drwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span> <span class="comment">258</span> <span class="comment">root</span> <span class="comment">root</span> <span class="comment">4096</span> <span class="comment">10月</span> <span class="comment">28</span> <span class="comment">14:42</span> <span class="comment">01</span>
<span class="comment">drwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span> <span class="comment">258</span> <span class="comment">root</span> <span class="comment">root</span> <span class="comment">4096</span> <span class="comment">10月</span> <span class="comment">28</span> <span class="comment">14:42</span> <span class="comment">02</span>
<span class="comment">drwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span> <span class="comment">258</span> <span class="comment">root</span> <span class="comment">root</span> <span class="comment">4096</span> <span class="comment">10月</span> <span class="comment">28</span> <span class="comment">14:42</span> <span class="comment">03</span>
<span class="comment">drwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span> <span class="comment">258</span> <span class="comment">root</span> <span class="comment">root</span> <span class="comment">4096</span> <span class="comment">10月</span> <span class="comment">28</span> <span class="comment">14:42</span> <span class="comment">04</span>
<span class="comment">drwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span> <span class="comment">258</span> <span class="comment">root</span> <span class="comment">root</span> <span class="comment">4096</span> <span class="comment">10月</span> <span class="comment">28</span> <span class="comment">14:42</span> <span class="comment">05</span>
<span class="comment">drwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span> <span class="comment">258</span> <span class="comment">root</span> <span class="comment">root</span> <span class="comment">4096</span> <span class="comment">10月</span> <span class="comment">28</span> <span class="comment">14:42</span> <span class="comment">06</span>
<span class="comment">drwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span> <span class="comment">258</span> <span class="comment">root</span> <span class="comment">root</span> <span class="comment">4096</span> <span class="comment">10月</span> <span class="comment">28</span> <span class="comment">14:42</span> <span class="comment">07</span>
<span class="comment">drwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span> <span class="comment">258</span> <span class="comment">root</span> <span class="comment">root</span> <span class="comment">4096</span> <span class="comment">10月</span> <span class="comment">28</span> <span class="comment">14:42</span> <span class="comment">08</span>
<span class="comment">drwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span> <span class="comment">258</span> <span class="comment">root</span> <span class="comment">root</span> <span class="comment">4096</span> <span class="comment">10月</span> <span class="comment">28</span> <span class="comment">14:42</span> <span class="comment">09</span>
<span class="comment">drwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span> <span class="comment">258</span> <span class="comment">root</span> <span class="comment">root</span> <span class="comment">4096</span> <span class="comment">10月</span> <span class="comment">28</span> <span class="comment">14:42</span> <span class="comment">0A</span>
<span class="comment">drwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span> <span class="comment">258</span> <span class="comment">root</span> <span class="comment">root</span> <span class="comment">4096</span> <span class="comment">10月</span> <span class="comment">28</span> <span class="comment">14:42</span> <span class="comment">0B</span>
<span class="comment">drwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span> <span class="comment">258</span> <span class="comment">root</span> <span class="comment">root</span> <span class="comment">4096</span> <span class="comment">10月</span> <span class="comment">28</span> <span class="comment">14:42</span> <span class="comment">0C</span>
<span class="comment">drwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span> <span class="comment">258</span> <span class="comment">root</span> <span class="comment">root</span> <span class="comment">4096</span> <span class="comment">10月</span> <span class="comment">28</span> <span class="comment">14:42</span> <span class="comment">0D</span>
<span class="comment">drwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span> <span class="comment">258</span> <span class="comment">root</span> <span class="comment">root</span> <span class="comment">4096</span> <span class="comment">10月</span> <span class="comment">28</span> <span class="comment">14:42</span> <span class="comment">0E</span>
<span class="comment">drwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span> <span class="comment">258</span> <span class="comment">root</span> <span class="comment">root</span> <span class="comment">4096</span> <span class="comment">10月</span> <span class="comment">28</span> <span class="comment">14:42</span> <span class="comment">0F</span>
<span class="comment">drwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span> <span class="comment">258</span> <span class="comment">root</span> <span class="comment">root</span> <span class="comment">4096</span> <span class="comment">10月</span> <span class="comment">28</span> <span class="comment">14:42</span> <span class="comment">10</span>
</code></pre>

<h4>5.修改 fastdfs的nginx模块的配置文件 mod_fastdfs.conf</h4>

<p>一般只需改动以下几个参数即可：</p>

<pre><code class="bash">
base_path=/data/fastdfs/storage      <span class="comment">#保存日志目录</span>
tracker_server=<span class="number">10.10</span>.<span class="number">10.124</span>:<span class="number">22122</span>    <span class="comment">#tracker 服务器的 IP 地址以及端口号</span>
storage_server_port=<span class="number">23000</span>            <span class="comment">#storage 服务器的端口号</span>
group_name=group1                    <span class="comment">#当前服务器的 group 名</span>
url_have_group_name = <span class="literal">true</span>           <span class="comment">#文件 url 中是否有 group 名</span>
store_path_count=<span class="number">1</span>                   <span class="comment">#存储路径个数，需要和 store_path 个数匹配</span>
store_path0=/data/fastdfs/storage    <span class="comment">#存储路径</span>
http.need_find_content_<span class="built_in">type</span>=<span class="literal">true</span>     <span class="comment"># 从文件 扩展 名查 找 文件 类型 （ nginx 时 为true）</span>
group_count = <span class="number">1</span>                      <span class="comment">#设置组的个数</span>
</code></pre>

<p>然后在末尾添加分组信息，目前只有一个分组，就只写一个</p>

<pre><code class="haskell">
[group1]
<span class="title">group_name</span>=group1
<span class="title">storage_server_port</span>=<span class="number">23000</span>
<span class="title">store_path_count</span>=<span class="number">1</span>
<span class="title">store_path0</span>=/<span class="keyword">data</span>/fastdfs/storage
</code></pre>

<h4>6.建立 M00 至存储目录的符号连接</h4>

<pre><code class="haskell">
[root@server1 fdfs]# ln -s /<span class="keyword">data</span>/fastdfs/storage/<span class="typedef"><span class="keyword">data</span> /<span class="keyword">data</span>/fastdfs/storage/<span class="keyword">data</span>/<span class="type">M00</span></span>
[root@server1 fdfs]# ll /<span class="keyword">data</span>/fastdfs/storage/<span class="keyword">data</span>/<span class="type">M00</span>
<span class="title">lrwxrwxrwx</span> <span class="number">1</span> root root <span class="number">26</span> <span class="number">10</span>月 <span class="number">29</span> <span class="number">11</span>:<span class="number">22</span> /<span class="keyword">data</span>/fastdfs/storage/<span class="keyword">data</span>/<span class="type">M00</span> -&gt; /<span class="keyword">data</span>/fastdfs/storage/<span class="keyword">data</span>
</code></pre>

<p>至此nginx和FastDFS 插件模块设置完成</p>

<h4>7.启动nginx</h4>

<pre><code class="r">
[root@server1 nginx]<span class="comment"># chmod u+x /etc/init.d/nginx</span>
[root@server1 nginx]<span class="comment"># chkconfig --add nginx</span>
[root@server1 nginx]<span class="comment"># chkconfig nginx on</span>
[root@server1 nginx]<span class="comment"># service nginx start</span>
正在启动 nginx：                                           [确定]
[root@server1 nginx]<span class="comment"># service nginx status</span>
nginx (pid <span class="number">26500</span>) 正在运行<span class="keyword">...</span>
</code></pre>

<p>查看nginx的日志 错误日志logs/error.log 看是否有问题</p>

<pre><code class="brainfuck">
<span class="title">[</span><span class="comment">2014</span><span class="literal">-</span><span class="comment">10</span><span class="literal">-</span><span class="comment">29</span> <span class="comment">14:35:29</span><span class="title">]</span> <span class="comment">INFO</span> <span class="literal">-</span> <span class="comment">local_host_ip_count:</span> <span class="comment">2</span><span class="string">,</span>  <span class="comment">127</span><span class="string">.</span><span class="comment">0</span><span class="string">.</span><span class="comment">0</span><span class="string">.</span><span class="comment">1</span>  <span class="comment">10</span><span class="string">.</span><span class="comment">10</span><span class="string">.</span><span class="comment">10</span><span class="string">.</span><span class="comment">120</span>
<span class="title">[</span><span class="comment">2014</span><span class="literal">-</span><span class="comment">10</span><span class="literal">-</span><span class="comment">29</span> <span class="comment">14:35:29</span><span class="title">]</span> <span class="comment">INFO</span> <span class="literal">-</span> <span class="comment">fastdfs</span> <span class="comment">apache</span> <span class="comment">/</span> <span class="comment">nginx</span> <span class="comment">module</span> <span class="comment">v1</span><span class="string">.</span><span class="comment">15</span><span class="string">,</span> <span class="comment">response_mode=proxy</span><span class="string">,</span> <span class="comment">base_path=/tmp</span><span class="string">,</span> <span class="comment">url_have_group_name=1</span><span class="string">,</span> <span class="comment">group_count=1</span><span class="string">,</span> <span class="comment">connect_timeout=2</span><span class="string">,</span> <span class="comment">network_timeout=30</span><span class="string">,</span> <span class="comment">tracker_server_count=1</span><span class="string">,</span> <span class="comment">if_alias_prefix=</span><span class="string">,</span> <span class="comment">local_host_ip_count=2</span><span class="string">,</span> <span class="comment">anti_steal_token=0</span><span class="string">,</span> <span class="comment">token_ttl=0s</span><span class="string">,</span> <span class="comment">anti_steal_secret_key</span> <span class="comment">length=0</span><span class="string">,</span> <span class="comment">token_check_fail</span> <span class="comment">content_type=</span><span class="string">,</span> <span class="comment">token_check_fail</span> <span class="comment">buff</span> <span class="comment">length=0</span><span class="string">,</span> <span class="comment">load_fdfs_parameters_from_tracker=1</span><span class="string">,</span> <span class="comment">storage_sync_file_max_delay=86400s</span><span class="string">,</span> <span class="comment">use_storage_id=0</span><span class="string">,</span> <span class="comment">storage</span> <span class="comment">server</span> <span class="comment">id</span> <span class="comment">count=0</span><span class="string">,</span> <span class="comment">flv_support=1</span><span class="string">,</span> <span class="comment">flv_extension=flv</span>
<span class="title">[</span><span class="comment">2014</span><span class="literal">-</span><span class="comment">10</span><span class="literal">-</span><span class="comment">29</span> <span class="comment">14:35:29</span><span class="title">]</span> <span class="comment">INFO</span> <span class="literal">-</span> <span class="comment">group</span> <span class="comment">1</span><span class="string">.</span> <span class="comment">group_name=group1</span><span class="string">,</span> <span class="comment">storage_server_port=23000</span><span class="string">,</span> <span class="comment">path_count=1</span><span class="string">,</span> <span class="comment">store_path0=/data/fastdfs/storage</span>
</code></pre>

<p>也可以访问 <a rel="nofollow" href="http://10.10.10.120:8080/">http://10.10.10.120:8080</a></p>

<p><img src="./FastDFS + Nginx 反向代理缓存 安装与配置 - The Soul of Linux_files/1183625055.png" alt="f43045e2-817a-4261-b0ee-4fab6c3fa546.png"></p>

<p>看到没什么错误，至此在storage1上安装配置nginx结束。</p>

<p>再在storage2上以相同的步骤来安装nginx。</p>

<h1>五、安装nginx反向代理及缓存服务器</h1>

<p>以下操作在 10.10.10.123 上操作</p>

<h4>1.安装nginx</h4>

<p>将所需的软件包上传至服务器/usr/local/src下</p>

<pre><code class="avrasm">
[root@fastdfs-nginx ~]<span class="preprocessor"># cd /usr/local/src/</span>
[root@fastdfs-nginx src]<span class="preprocessor"># ls</span>
[root@fastdfs-nginx src]<span class="preprocessor"># rz</span>
rz waiting to receive.
Starting zmodem transfer.  Press Ctrl+C to cancel.
Transferring nginx-<span class="number">1.4</span><span class="number">.7</span><span class="preprocessor">.tar</span><span class="preprocessor">.gz</span>...
  <span class="number">100</span>%     <span class="number">751</span> KB     <span class="number">751</span> KB/<span class="keyword">sec</span>    <span class="number">00</span>:<span class="number">00</span>:<span class="number">01</span>       <span class="number">0</span> Errors  
Transferring ngx_cache_purge-<span class="number">2.1</span><span class="preprocessor">.tar</span><span class="preprocessor">.gz</span>...
  <span class="number">100</span>%      <span class="number">10</span> KB      <span class="number">10</span> KB/<span class="keyword">sec</span>    <span class="number">00</span>:<span class="number">00</span>:<span class="number">01</span>       <span class="number">0</span> Errors  
Transferring pcre-<span class="number">8.36</span><span class="preprocessor">.tar</span><span class="preprocessor">.gz</span>...
  <span class="number">100</span>%    <span class="number">1962</span> KB    <span class="number">1962</span> KB/<span class="keyword">sec</span>    <span class="number">00</span>:<span class="number">00</span>:<span class="number">01</span>       <span class="number">0</span> Errors  
Transferring zlib-<span class="number">1.2</span><span class="number">.8</span><span class="preprocessor">.tar</span><span class="preprocessor">.gz</span>...
  <span class="number">100</span>%     <span class="number">557</span> KB     <span class="number">557</span> KB/<span class="keyword">sec</span>    <span class="number">00</span>:<span class="number">00</span>:<span class="number">01</span>       <span class="number">0</span> Errors  
</code></pre>

<p>解压各个软件包</p>

<pre><code class="brainfuck">
<span class="title">[</span><span class="comment">root@fastdfs</span><span class="literal">-</span><span class="comment">nginx</span> <span class="comment">src</span><span class="title">]</span><span class="comment">#</span> <span class="comment">tar</span> <span class="comment">xf</span> <span class="comment">nginx</span><span class="literal">-</span><span class="comment">1</span><span class="string">.</span><span class="comment">4</span><span class="string">.</span><span class="comment">7</span><span class="string">.</span><span class="comment">tar</span><span class="string">.</span><span class="comment">gz</span> 
<span class="title">[</span><span class="comment">root@fastdfs</span><span class="literal">-</span><span class="comment">nginx</span> <span class="comment">src</span><span class="title">]</span><span class="comment">#</span> <span class="comment">tar</span> <span class="comment">xf</span> <span class="comment">ngx_cache_purge</span><span class="literal">-</span><span class="comment">2</span><span class="string">.</span><span class="comment">1</span><span class="string">.</span><span class="comment">tar</span><span class="string">.</span><span class="comment">gz</span> 
<span class="title">[</span><span class="comment">root@fastdfs</span><span class="literal">-</span><span class="comment">nginx</span> <span class="comment">src</span><span class="title">]</span><span class="comment">#</span> <span class="comment">tar</span> <span class="comment">xf</span> <span class="comment">pcre</span><span class="literal">-</span><span class="comment">8</span><span class="string">.</span><span class="comment">36</span><span class="string">.</span><span class="comment">tar</span><span class="string">.</span><span class="comment">gz</span> 
<span class="title">[</span><span class="comment">root@fastdfs</span><span class="literal">-</span><span class="comment">nginx</span> <span class="comment">src</span><span class="title">]</span><span class="comment">#</span> <span class="comment">tar</span> <span class="comment">xf</span> <span class="comment">zlib</span><span class="literal">-</span><span class="comment">1</span><span class="string">.</span><span class="comment">2</span><span class="string">.</span><span class="comment">8</span><span class="string">.</span><span class="comment">tar</span><span class="string">.</span><span class="comment">gz</span> 
<span class="title">[</span><span class="comment">root@fastdfs</span><span class="literal">-</span><span class="comment">nginx</span> <span class="comment">src</span><span class="title">]</span><span class="comment">#</span> <span class="comment">cd</span> <span class="comment">nginx</span><span class="literal">-</span><span class="comment">1</span><span class="string">.</span><span class="comment">4</span><span class="string">.</span><span class="comment">7</span>
</code></pre>

<p>编译安装nginx</p>

<pre><code class="r">
[root@fastdfs-nginx nginx-<span class="number">1.4</span><span class="number">.7</span>]<span class="comment"># ./configure  --prefix=/usr/local/nginx  --add-module=/usr/local/src/ngx_cache_purge-2.1  --with-pcre=/usr/local/src/pcre-8.36/  --with-zlib=/usr/local/src/zlib-1.2.8</span>
checking <span class="keyword">for</span> OS
 + Linux <span class="number">2.6</span><span class="number">.32</span>-<span class="number">431.</span>el6.x86_64 x86_64
checking <span class="keyword">for</span> C compiler <span class="keyword">...</span> found
 + using GNU C compiler
 + gcc version: <span class="number">4.4</span><span class="number">.7</span> <span class="number">20120313</span> (Red Hat <span class="number">4.4</span><span class="number">.7</span>-<span class="number">4</span>) (GCC) 
checking <span class="keyword">for</span> gcc -pipe <span class="keyword">switch</span> <span class="keyword">...</span> found
checking <span class="keyword">for</span> gcc builtin atomic operations <span class="keyword">...</span> found
checking <span class="keyword">for</span> C99 variadic macros <span class="keyword">...</span> found
checking <span class="keyword">for</span> gcc variadic macros <span class="keyword">...</span> found
checking <span class="keyword">for</span> unistd.h <span class="keyword">...</span> found
checking <span class="keyword">for</span> inttypes.h <span class="keyword">...</span> found
<span class="keyword">...</span>
Configuration summary
  + using PCRE <span class="keyword">library</span>: /usr/local/src/pcre-<span class="number">8.36</span>/
  + OpenSSL <span class="keyword">library</span> is not used
  + md5: using system crypto <span class="keyword">library</span>
  + sha1: using system crypto <span class="keyword">library</span>
  + using zlib <span class="keyword">library</span>: /usr/local/src/zlib-<span class="number">1.2</span><span class="number">.8</span>
  nginx path prefix: <span class="string">"/usr/local/nginx"</span>
  nginx binary file: <span class="string">"/usr/local/nginx/sbin/nginx"</span>
  nginx configuration prefix: <span class="string">"/usr/local/nginx/conf"</span>
  nginx configuration file: <span class="string">"/usr/local/nginx/conf/nginx.conf"</span>
  nginx pid file: <span class="string">"/usr/local/nginx/logs/nginx.pid"</span>
  nginx error log file: <span class="string">"/usr/local/nginx/logs/error.log"</span>
  nginx http access log file: <span class="string">"/usr/local/nginx/logs/access.log"</span>
  nginx http client request body temporary files: <span class="string">"client_body_temp"</span>
  nginx http proxy temporary files: <span class="string">"proxy_temp"</span>
  nginx http fastcgi temporary files: <span class="string">"fastcgi_temp"</span>
  nginx http uwsgi temporary files: <span class="string">"uwsgi_temp"</span>
  nginx http scgi temporary files: <span class="string">"scgi_temp"</span>
[root@fastdfs-nginx nginx-<span class="number">1.4</span><span class="number">.7</span>]<span class="comment"># make &amp;&amp; make install</span>
</code></pre>

<p>至此 nginx 以及 nginx cache purge 插件模块安装完成。</p>

<h4>2.配置</h4>

<p>准备nginx的启动脚本，内容同上面的storage安装时的脚本，并加入到系统的服务，开机启动</p>

<p>创建nginx的缓存目录</p>

<pre><code class="perl">
[root<span class="variable">@fastdfs</span>-nginx nginx]<span class="comment"># mkdir -pv /var/cache/nginx/proxy_cache/tmp</span>
<span class="keyword">mkdir</span>: 已创建目录 <span class="string">"/var/cache/nginx"</span>
<span class="keyword">mkdir</span>: 已创建目录 <span class="string">"/var/cache/nginx/proxy_cache"</span>
<span class="keyword">mkdir</span>: 已创建目录 <span class="string">"/var/cache/nginx/proxy_cache/tmp"</span>
</code></pre>

<p>增加系统打开文件数的限制</p>

<pre><code class="brainfuck">
<span class="title">[</span><span class="comment">root@fastdfs</span><span class="literal">-</span><span class="comment">nginx</span> <span class="comment">nginx</span><span class="title">]</span><span class="comment">#</span> <span class="comment">ulimit</span> <span class="literal">-</span><span class="comment">SHn</span> <span class="comment">102400</span>
<span class="title">[</span><span class="comment">root@fastdfs</span><span class="literal">-</span><span class="comment">nginx</span> <span class="comment">nginx</span><span class="title">]</span><span class="comment">#</span> <span class="comment">echo</span> <span class="comment">"ulimit</span> <span class="literal">-</span><span class="comment">SHn</span> <span class="comment">102400"</span> &gt;&gt; <span class="comment">/etc/rc</span><span class="string">.</span><span class="comment">local</span>
</code></pre>

<p>编辑  vim /usr/local/nginx/conf/nginx.conf 文件修改以下内容:</p>

<pre><code class="nginx">
<span class="title">user</span>  nobody;
<span class="title">worker_processes</span>  <span class="number">1</span>;
<span class="title">error_log</span>  logs/error.log  <span class="built_in">info</span>;
<span class="title">pid</span>        logs/nginx.pid;
<span class="title">events</span> {
    <span class="title">worker_connections</span>  <span class="number">65535</span>;
    <span class="title">use</span> <span class="built_in">epoll</span>;
}
<span class="title">http</span> {
    <span class="title">include</span>       mime.types;
    <span class="title">default_type</span>  application/octet-stream;
    <span class="title">sendfile</span>        <span class="built_in">on</span>;
    <span class="title">tcp_nopush</span>     <span class="built_in">on</span>;
    <span class="title">keepalive_timeout</span>  <span class="number">65</span>;
    <span class="title">server_names_hash_bucket_size</span> <span class="number">128</span>;
    <span class="title">client_header_buffer_size</span> <span class="number">32k</span>;
    <span class="title">large_client_header_buffers</span> <span class="number">4</span> <span class="number">32k</span>;
    <span class="title">client_max_body_size</span> <span class="number">300m</span>;
    <span class="title">proxy_redirect</span> <span class="built_in">off</span>;
    <span class="title">proxy_set_header</span> Host <span class="variable">$http_host</span>;
    <span class="title">proxy_set_header</span> X-Real-IP <span class="variable">$remote_addr</span>;
    <span class="title">proxy_set_header</span> X-Forwarded-For <span class="variable">$proxy_add_x_forwarded_for</span>;
    <span class="title">proxy_connect_timeout</span> <span class="number">90</span>;
    <span class="title">proxy_send_timeout</span> <span class="number">90</span>;
    <span class="title">proxy_read_timeout</span> <span class="number">90</span>;
    <span class="title">proxy_buffer_size</span> <span class="number">16k</span>;
    <span class="title">proxy_buffers</span> <span class="number">4</span> <span class="number">64k</span>;
    <span class="title">proxy_busy_buffers_size</span> <span class="number">128k</span>;
    <span class="title">proxy_temp_file_write_size</span> <span class="number">128k</span>;
    <span class="comment">#设置缓存存储路径、存储方式、分配内存大小、磁盘最大空间、缓存期限</span>
    <span class="title">proxy_cache_path</span>  /var/cache/nginx/proxy_cache  levels=<span class="number">1</span>:<span class="number">2</span>
    keys_zone=http-cache:<span class="number">500m</span> max_size=<span class="number">10g</span> inactive=<span class="number">30d</span>;
    <span class="title">proxy_temp_path</span> /var/cache/nginx/proxy_cache/tmp;
    <span class="comment">#设置 group1 的服务器</span>
    <span class="title">upstream</span> fdfs_group1 {
        <span class="title">server</span> <span class="number">10.10.10.120:8080</span> weight=<span class="number">1</span> max_fails=<span class="number">2</span> fail_timeout=<span class="number">30s</span>;
        <span class="title">server</span> <span class="number">10.10.10.122:8080</span> weight=<span class="number">1</span> max_fails=<span class="number">2</span> fail_timeout=<span class="number">30s</span>;
    }
    <span class="title">log_format</span>  main  <span class="string">'<span class="variable">$remote_addr</span> - <span class="variable">$remote_user</span> [<span class="variable">$time_local</span>] "<span class="variable">$request</span>" '</span>
                      <span class="string">'<span class="variable">$status</span> <span class="variable">$body_bytes_sent</span> "<span class="variable">$http_referer</span>" '</span>
                      <span class="string">'"<span class="variable">$http_user_agent</span>" "<span class="variable">$http_x_forwarded_for</span>"'</span>;
    <span class="title">server</span> {
        <span class="title">listen</span>       <span class="number">80</span>;
        <span class="title">server_name</span>  localhost;
        <span class="title">access_log</span>  logs/host.access.log  main;
    <span class="comment">#设置 group1 的反向代理参数</span>
    <span class="title">location</span> /group1/M00 {
        <span class="title">proxy_next_upstream</span> http_502 http_504 <span class="built_in">error</span> timeout invalid_header;
        <span class="title">proxy_cache</span> http-cache;
        <span class="title">proxy_cache_valid</span> <span class="number">200</span> <span class="number">304</span> <span class="number">12h</span>;
        <span class="title">proxy_cache_key</span> <span class="variable">$uri</span><span class="variable">$is_args</span><span class="variable">$args</span>;
        <span class="title">proxy_pass</span> <span class="url">http://fdfs_group1</span>;
        <span class="title">expires</span> <span class="number">30d</span>;
    }
    <span class="comment">#设置清除缓存的访问权限</span>
        <span class="title">location</span> <span class="regexp">~ /purge(/.*)</span> {
        <span class="title">allow</span> <span class="number">127.0.0.1</span>;
        <span class="title">allow</span> <span class="number">10.10.10.0</span>/<span class="number">24</span>;
        <span class="title">deny</span> all;
        <span class="title">proxy_cache_purge</span> http-cache <span class="variable">$1</span><span class="variable">$is_args</span><span class="variable">$args</span>;
    } 
    }
}
</code></pre>

<p>使用 /usr/local/nginx/sbin/nginx -t 来测试配置文件语法的正确性</p>

<pre><code class="applescript">
[root@fastdfs-nginx nginx]<span class="comment"># ./sbin/nginx -t</span>
nginx: <span class="keyword">the</span> configuration <span class="type">file</span> /usr/<span class="keyword">local</span>/nginx/conf/nginx.conf syntax <span class="keyword">is</span> ok
nginx: configuration <span class="type">file</span> /usr/<span class="keyword">local</span>/nginx/conf/nginx.conf test <span class="keyword">is</span> successful
</code></pre>

<h4>3.启动nginx</h4>

<pre><code class="ruby">
[root<span class="variable">@fastdfs</span>-nginx nginx]<span class="comment"># service nginx start</span>
正在启动 nginx：                                           [确定]
</code></pre>

<p>查看监听的端口</p>

<pre><code class="ruby">
[root<span class="variable">@fastdfs</span>-nginx conf]<span class="comment"># netstat -antp | grep nginx</span>
tcp        <span class="number">0</span>      <span class="number">0</span> <span class="number">0</span>.<span class="number">0</span>.<span class="number">0</span>.<span class="number">0</span><span class="symbol">:</span><span class="number">80</span>                  <span class="number">0</span>.<span class="number">0</span>.<span class="number">0</span>.<span class="number">0</span><span class="symbol">:*</span>                   <span class="constant">LISTEN</span>      <span class="number">20526</span>/nginx         
[root<span class="variable">@fastdfs</span>-nginx conf]<span class="comment"># </span>
</code></pre>

<h1>六、测试上传文件</h1>

<p>以下操作在tracker服务器（10.10.10.124）上进行</p>

<h4>1.创建client 使用的日志目录</h4>

<pre><code class="perl">
[root<span class="variable">@tracker</span> tracker]<span class="comment"># mkdir -pv /data/fastdfs/client</span>
<span class="keyword">mkdir</span>: 已创建目录 <span class="string">"/data/fastdfs/client"</span>
</code></pre>

<h4>2. 修改客户端的配置文件/etc/fdfs/client.conf</h4>

<p>修改以下参数即可：</p>

<pre><code class="haskell">
<span class="title">base_path</span>=/<span class="keyword">data</span>/fastdfs/client #日志存放路径
<span class="title">tracker_server</span>=<span class="number">10.10</span><span class="number">.10</span><span class="number">.124</span>:<span class="number">22122</span> #tracker 服务器 <span class="type">IP</span> 地址和端口号
<span class="title">http</span>.tracker_server_port=<span class="number">8080</span> #tracker 服务器的 http 端口号 ，这一项感觉没什么用处，tracker都没有启用http服务
</code></pre>

<h4>3.上传一个图片</h4>

<pre><code class="ruby">
[root<span class="variable">@tracker</span> ~]<span class="comment"># fdfs_upload_file /etc/fdfs/client.conf 1.jpg</span>
group1/<span class="constant">M00</span>/<span class="number">00</span>/<span class="number">00</span>/<span class="constant">CgoKeFRQqaaASsgNAAEgRqu1UiU712</span>.jpg
[root<span class="variable">@tracker</span> ~]<span class="comment"># </span>
</code></pre>

<p>得到了一个如上的一个地址 group1/M00/00/00/CgoKeFRQqaaASsgNAAEgRqu1UiU712.jpg</p>

<p>可以使用fdfs_file_info 来查看上传文件的信息</p>

<pre><code class="coffeescript">
[root<span class="property">@tracker</span> ~]<span class="comment"># fdfs_file_info /etc/fdfs/client.conf group1/M00/00/00/CgoKeFRQqaaASsgNAAEgRqu1UiU712.jpg</span>
source storage <span class="attribute">id</span>: <span class="number">0</span>
source ip <span class="attribute">address</span>: <span class="number">10.10</span><span class="number">.10</span><span class="number">.120</span>
file create <span class="attribute">timestamp</span>: <span class="number">2014</span>-<span class="number">10</span>-<span class="number">29</span> <span class="number">16</span>:<span class="number">47</span>:<span class="number">34</span>
file <span class="attribute">size</span>: <span class="number">73798</span>
file <span class="attribute">crc32</span>: <span class="number">2880786981</span> (<span class="number">0xABB55225</span>)
</code></pre>

<p>这个信息里面可以看到 这个文件上传的时候 首先上传到了10.10.10.120这台服务器，文件的创建时间、文件的大小</p>

<h4>4.使用浏览器访问一下该地址</h4>

<p>完整的URL是这样的  <a rel="nofollow" href="http://10.10.10.123/group1/M00/00/00/CgoKeFRQqaaASsgNAAEgRqu1UiU712.jpg">http://10.10.10.123/group1/M00/00/00/CgoKeFRQqaaASsgNAAEgRqu1UiU712.jpg</a></p>

<p>10.10.10.123 就是nginx反向代理缓存服务器</p>

<p><img src="./FastDFS + Nginx 反向代理缓存 安装与配置 - The Soul of Linux_files/4180196198.jpg" alt="9cbebcdc-6a10-4c87-832f-b4aa8b8a0a60.jpg"></p>

<p>成功访问到图片</p>

<p>查看一下nginx的访问日志，可以看到状态码是 200OK.</p>

<pre><code class="brainfuck">
<span class="title">[</span><span class="comment">root@fastdfs</span><span class="literal">-</span><span class="comment">nginx</span> <span class="comment">~</span><span class="title">]</span><span class="comment">#</span> <span class="comment">tail</span> <span class="literal">-</span><span class="comment">1</span> <span class="comment">/usr/local/nginx/logs/host</span><span class="string">.</span><span class="comment">access</span><span class="string">.</span><span class="comment">log</span> 
<span class="comment">10</span><span class="string">.</span><span class="comment">10</span><span class="string">.</span><span class="comment">10</span><span class="string">.</span><span class="comment">46</span> <span class="literal">-</span> <span class="literal">-</span> <span class="title">[</span><span class="comment">29/Oct/2014:16:48:43</span> <span class="literal">+</span><span class="comment">0800</span><span class="title">]</span> <span class="comment">"GET</span> <span class="comment">/group1/M00/00/00/CgoKeFRQqaaASsgNAAEgRqu1UiU712</span><span class="string">.</span><span class="comment">jpg</span> <span class="comment">HTTP/1</span><span class="string">.</span><span class="comment">1"</span> <span class="comment">200</span> <span class="comment">73798</span> <span class="comment">"</span><span class="literal">-</span><span class="comment">"</span> <span class="comment">"Mozilla/5</span><span class="string">.</span><span class="comment">0</span> <span class="comment">(Windows</span> <span class="comment">NT</span> <span class="comment">6</span><span class="string">.</span><span class="comment">1)</span> <span class="comment">AppleWebKit/537</span><span class="string">.</span><span class="comment">36</span> <span class="comment">(KHTML</span><span class="string">,</span> <span class="comment">like</span> <span class="comment">Gecko)</span> <span class="comment">Chrome/35</span><span class="string">.</span><span class="comment">0</span><span class="string">.</span><span class="comment">1916</span><span class="string">.</span><span class="comment">153</span> <span class="comment">Safari/537</span><span class="string">.</span><span class="comment">36"</span> <span class="comment">"</span><span class="literal">-</span><span class="comment">"</span>
<span class="title">[</span><span class="comment">root@fastdfs</span><span class="literal">-</span><span class="comment">nginx</span> <span class="comment">~</span><span class="title">]</span><span class="comment">#</span> 
</code></pre>

<p>查看nginx的缓存目录，看是否已经缓存成功</p>

<pre><code class="brainfuck">
<span class="title">[</span><span class="comment">root@fastdfs</span><span class="literal">-</span><span class="comment">nginx</span> <span class="comment">~</span><span class="title">]</span><span class="comment">#</span> <span class="comment">ll</span> <span class="literal">-</span><span class="comment">R</span> <span class="comment">/var/cache/nginx/proxy_cache/</span> 
<span class="comment">/var/cache/nginx/proxy_cache/:</span>
<span class="comment">总用量</span> <span class="comment">8</span>
<span class="comment">drwx</span><span class="literal">-</span><span class="literal">-</span><span class="literal">-</span><span class="literal">-</span><span class="literal">-</span><span class="literal">-</span><span class="string">.</span> <span class="comment">3</span> <span class="comment">nobody</span> <span class="comment">nobody</span> <span class="comment">4096</span> <span class="comment">10月</span> <span class="comment">29</span> <span class="comment">16:47</span> <span class="comment">e</span>
<span class="comment">drwxr</span><span class="literal">-</span><span class="comment">xr</span><span class="literal">-</span><span class="comment">x</span><span class="string">.</span> <span class="comment">2</span> <span class="comment">nobody</span> <span class="comment">root</span>   <span class="comment">4096</span> <span class="comment">10月</span> <span class="comment">29</span> <span class="comment">16:47</span> <span class="comment">tmp</span>
<span class="comment">/var/cache/nginx/proxy_cache/e:</span>
<span class="comment">总用量</span> <span class="comment">4</span>
<span class="comment">drwx</span><span class="literal">-</span><span class="literal">-</span><span class="literal">-</span><span class="literal">-</span><span class="literal">-</span><span class="literal">-</span><span class="string">.</span> <span class="comment">2</span> <span class="comment">nobody</span> <span class="comment">nobody</span> <span class="comment">4096</span> <span class="comment">10月</span> <span class="comment">29</span> <span class="comment">16:47</span> <span class="comment">a8</span>
<span class="comment">/var/cache/nginx/proxy_cache/e/a8:</span>
<span class="comment">总用量</span> <span class="comment">76</span>
<span class="literal">-</span><span class="comment">rw</span><span class="literal">-</span><span class="literal">-</span><span class="literal">-</span><span class="literal">-</span><span class="literal">-</span><span class="literal">-</span><span class="literal">-</span><span class="string">.</span> <span class="comment">1</span> <span class="comment">nobody</span> <span class="comment">nobody</span> <span class="comment">74110</span> <span class="comment">10月</span> <span class="comment">29</span> <span class="comment">16:47</span> <span class="comment">54408edb44f74ab4da965506f54a6a8e</span>  <span class="comment">在此已经缓存成功</span>
<span class="comment">/var/cache/nginx/proxy_cache/tmp:</span>
<span class="comment">总用量</span> <span class="comment">0</span>
<span class="title">[</span><span class="comment">root@fastdfs</span><span class="literal">-</span><span class="comment">nginx</span> <span class="comment">~</span><span class="title">]</span><span class="comment">#</span> 
</code></pre>

<h4>5. 清除缓存</h4>

<p>若要清除该图片的缓存，可以在文件 URL 之前加上 purge 即可，如下图</p>

<p><a rel="nofollow" href="http://10.10.10.123/purge/group1/M00/00/00/CgoKeFRQqaaASsgNAAEgRqu1UiU712.jpg">http://10.10.10.123/purge/group1/M00/00/00/CgoKeFRQqaaASsgNAAEgRqu1UiU712.jpg</a></p>

<p><img src="./FastDFS + Nginx 反向代理缓存 安装与配置 - The Soul of Linux_files/3149652324.png" alt="51d9faa5-2039-4d3a-955a-dca42c148673.png"></p>

<h4>6. 配置浏览器端查看是否命中缓存</h4>

<p>可以使用Chrome浏览器的开发工具，查看响应的头部信息来查看是否命中缓存，要启用此功能，修改nginx的主配置文件如下:</p>

<p>在location /group1/M00  段增加这2个行</p>

<pre><code class="lasso">
add_header  X<span class="attribute">-Via</span>  <span class="variable">$server_addr</span>;
add_header  X<span class="attribute">-Cache</span><span class="attribute">-Status</span> <span class="variable">$upstream_cache_status</span>;
</code></pre>

<p>最终效果</p>

<pre><code class="nginx">
<span class="title">location</span> /group1/M00 {
                <span class="title">proxy_next_upstream</span> http_502 http_504 <span class="built_in">error</span> timeout invalid_header;
                <span class="title">proxy_cache</span> http-cache;
                <span class="title">proxy_cache_valid</span> <span class="number">200</span> <span class="number">304</span> <span class="number">12h</span>;
                <span class="title">proxy_cache_key</span> <span class="variable">$uri</span><span class="variable">$is_args</span><span class="variable">$args</span>;
                <span class="title">proxy_pass</span> <span class="url">http://fdfs_group1</span>;
                <span class="title">expires</span> <span class="number">30d</span>;
                <span class="title">add_header</span>  X-Via  <span class="variable">$server_addr</span>;
                <span class="title">add_header</span>  X-Cache-Status <span class="variable">$upstream_cache_status</span>;
        }
</code></pre>

<p>重启nginx</p>

<pre><code class="lasso">
<span class="preprocessor">[</span>root@fastdfs<span class="attribute">-nginx</span> ~<span class="preprocessor">]</span><span class="markup"># service nginx restart
停止 nginx：                                               </span><span class="preprocessor">[</span>确定<span class="preprocessor">]</span><span class="markup">
正在启动 nginx：                                           </span><span class="preprocessor">[</span>确定<span class="preprocessor">]</span><span class="markup">
</span><span class="preprocessor">[</span>root@fastdfs<span class="attribute">-nginx</span> ~<span class="preprocessor">]</span><span class="markup"># 
</span></code></pre>

<p>清空chrome浏览器的缓存，清除那张图片在nginx中的缓存</p>

<p>第一次访问</p>

<p><img src="./FastDFS + Nginx 反向代理缓存 安装与配置 - The Soul of Linux_files/2947199333.jpg" alt="0917a394-fa6e-4b8f-80c0-d28fd18a77a6.jpg"></p>

<p>显示MISS,代表缓存中没有</p>

<p>第二次 ctrl+F5 强制刷新访问</p>

<p><img src="./FastDFS + Nginx 反向代理缓存 安装与配置 - The Soul of Linux_files/2249193973.jpg" alt="d4d53a07-64f1-4324-a447-57e854a353ba.jpg"></p>

<p>已经显示HIT，代表已经命中缓存</p>

<p>至此 FastDFS + nginx 反向代理缓存搭建完毕。</p>

<h1>七、优化部分</h1>

<h4>1、Tracker优化</h4>

<pre><code class="markdown">1)    max_connections=10000或更大响应参数增大内存消耗增加该参数需修改单一进程同时可打开文件数量（<span class="bullet">* soft nofile 65536 *</span> hard nofile 65536）的限制后生效。
2)    work_threads=12 cpu数量此处设置cpu核心数量
3)    thread<span class="emphasis">_stack_</span>size=256
测试配置如下
</code></pre>

<pre><code class="undefined">
 work_threads=12
    thread_stack_size=256
    max_connections=65535
</code></pre>

<h4>2、Storage优化</h4>

<pre><code class="haskell"><span class="title">work_threads</span>= work_threads + <span class="number">1</span> + (disk_reader_threads + disk_writer_threads) * store_path_count= <span class="number">15</span>

<span class="title">disk_rw_separated</span>：磁盘读写是否分离
<span class="title">disk_reader_threads</span>：单个磁盘读线程数
<span class="title">disk_writer_threads</span>：单个磁盘写线程数
如果磁盘读写混合，单个磁盘读写线程数为读线程数和写线程数之后
对于单盘挂载方式，磁盘读写线程分别设置为<span class="number">1</span>即可
如果磁盘做了<span class="type">RAID</span>，那么需要酌情加大读写线程数，这样才能最大程度地发挥磁盘性能
<span class="title">buff_size</span>=<span class="number">512</span>增大提升磁盘<span class="type">IO</span>的另外一个技巧，一次尽可能多写入或多读取。也就是说，将程序的读写buffer设置得尽可能大一些。例如日志或者redo log的写入，不是每次调用都直接写磁盘，而是先缓存到内存中，等buffer满了再写入磁盘，也可以定时写入磁盘。
测试配置如下
</code></pre>

<pre><code class="haskell">
<span class="title">thread_stack_size</span>=<span class="number">512</span>KB  
    disk_reader_threads = <span class="number">4</span>
    disk_writer_threads = <span class="number">4</span>
    buff_size=<span class="number">512</span>
    max_connections=<span class="number">65535</span>
    accept_threads=<span class="number">10</span>
    work_threads=<span class="number">16</span>a
</code></pre>

<p>以上配置压力测试上传并发2w 事务平均响应时间0.46秒，4w事务平均响应时间2.2秒。</p>

<h1>八、FastDFS使用流程</h1>

<h4>1.上传文件</h4>

<p><img src="./FastDFS + Nginx 反向代理缓存 安装与配置 - The Soul of Linux_files/1450337281.jpg" alt="3c718e5f-042f-4b59-9b30-bfc3d78c8109.jpg"></p>

<p>FastDFS 提供了多种方式上传文件：</p>

<pre><code class="avrasm">使用 fdfs_upload_file 上传
使用 C 语言客户端接口上传
使用 PHP 客户端接口上传
使用 Java 客户端接口上传
使用 Python 客户端接口上传
使用<span class="preprocessor">.NET</span> 客户端接口上传
</code></pre>

<p>根据具体情况选择使用。上传均支持断点续传。</p>

<p>如果Java的客户端，在API的配置文件中配置 tracker服务器，如果有多个tracker服务器，就配置多台</p>

<p>WEB-INF/classes/fdfs_client.conf</p>

<pre><code class="haskell">
<span class="title">connect_timeout</span> = <span class="number">2</span>
<span class="title">network_timeout</span> = <span class="number">30</span>
<span class="title">charset</span> = <span class="type">UTF</span>-<span class="number">8</span>
<span class="title">http</span>.tracker_http_port = <span class="number">8080</span>
<span class="title">http</span>.anti_steal_token = no
<span class="title">http</span>.secret_key = <span class="type">FastDFS1234567890</span>
 
<span class="title">tracker_server</span> =<span class="number">192.168</span><span class="number">.10</span><span class="number">.27</span>:<span class="number">22122</span>
<span class="title">tracker_server</span> = <span class="number">192.168</span><span class="number">.10</span><span class="number">.28</span>:<span class="number">22122</span>
</code></pre>

<h4>2.下载文件</h4>

<p><img src="./FastDFS + Nginx 反向代理缓存 安装与配置 - The Soul of Linux_files/1335223578.jpg" alt="5c154184-c88d-419a-8f1d-ad602cefe304.jpg"></p>

<pre><code class="livecodeserver">使用 fdfs_download_file 通过 tracker 服务器下载
使用 nginx 通过 <span class="keyword">http</span> 方式直接从 storage 下载（支持断点续传，作者推荐）
</code></pre>

<h4>3.监视服务器资源</h4>

<p>使用 fdfs_monitor 查看 tracker 和所有 group 的运行情况</p>

<pre><code class="applescript">
[root@tracker ~]<span class="comment"># fdfs_monitor /etc/fdfs/client.conf</span>
[<span class="number">2014</span>-<span class="number">10</span>-<span class="number">31</span> <span class="number">14</span>:<span class="number">09</span>:<span class="number">20</span>] DEBUG - base_path=/data/fastdfs/client, connect_timeout=<span class="number">30</span>, network_timeout=<span class="number">60</span>, tracker_server_count=<span class="number">1</span>, anti_steal_token=<span class="number">0</span>, anti_steal_secret_key <span class="property">length</span>=<span class="number">0</span>, use_connection_pool=<span class="number">0</span>, g_connection_pool_max_idle_time=<span class="number">3600</span>s, use_storage_id=<span class="number">0</span>, storage server <span class="property">id</span> <span class="command">count</span>: <span class="number">0</span>
 
server_count=<span class="number">1</span>, server_index=<span class="number">0</span>
 
tracker server <span class="keyword">is</span> <span class="number">10.10</span><span class="number">.10</span><span class="number">.124</span>:<span class="number">22122</span>
 
group <span class="command">count</span>: <span class="number">1</span>
 
Group <span class="number">1</span>:
group <span class="property">name</span> = group1
disk total <span class="constant">space</span> = <span class="number">14020</span> MB
disk free <span class="constant">space</span> = <span class="number">10224</span> MB
trunk free <span class="constant">space</span> = <span class="number">0</span> MB
storage server <span class="command">count</span> = <span class="number">2</span>
active server <span class="command">count</span> = <span class="number">2</span>
storage server port = <span class="number">23000</span>
storage HTTP port = <span class="number">8080</span>
store path <span class="command">count</span> = <span class="number">1</span>
subdir <span class="command">count</span> per path = <span class="number">256</span>
current <span class="command">write</span> server index = <span class="number">1</span>
current trunk <span class="type">file</span> <span class="property">id</span> = <span class="number">0</span>
 
        Storage <span class="number">1</span>:
                <span class="property">id</span> = <span class="number">10.10</span><span class="number">.10</span><span class="number">.120</span>
                ip_addr = <span class="number">10.10</span><span class="number">.10</span><span class="number">.120</span>  ACTIVE
                http domain =
                <span class="property">version</span> = <span class="number">5.04</span>
                join <span class="property">time</span> = <span class="number">2014</span>-<span class="number">10</span>-<span class="number">28</span> <span class="number">14</span>:<span class="number">42</span>:<span class="number">43</span>
                up <span class="property">time</span> = <span class="number">2014</span>-<span class="number">10</span>-<span class="number">29</span> <span class="number">14</span>:<span class="number">14</span>:<span class="number">44</span>
                total storage = <span class="number">14020</span> MB
....
 Storage <span class="number">2</span>:
                <span class="property">id</span> = <span class="number">10.10</span><span class="number">.10</span><span class="number">.122</span>
                ip_addr = <span class="number">10.10</span><span class="number">.10</span><span class="number">.122</span>  ACTIVE
                http domain = 
                <span class="property">version</span> = <span class="number">5.04</span>
                join <span class="property">time</span> = <span class="number">2014</span>-<span class="number">10</span>-<span class="number">28</span> <span class="number">15</span>:<span class="number">53</span>:<span class="number">51</span>
                up <span class="property">time</span> = <span class="number">2014</span>-<span class="number">10</span>-<span class="number">28</span> <span class="number">15</span>:<span class="number">53</span>:<span class="number">51</span>
                total storage = <span class="number">14020</span> MB
....
</code></pre>

<h4>4.其他功能</h4>

<pre><code class="undefined">使用 fdfs_crc32 获取文件 CRC
使用 fdfs_delete_file 删除文件
使用 fdfs_file_info 查看文件属性信息
</code></pre>        </div>
        <p class="tags">标签：<a href="http://www.linux178.com/tag/fastdfs/">fastdfs</a>, <a href="http://www.linux178.com/tag/nginx/">nginx</a>, <a href="http://www.linux178.com/tag/%E5%88%86%E5%B8%83%E5%BC%8F%E5%AD%98%E5%82%A8/">分布式存储</a>, <a href="http://www.linux178.com/tag/%E5%88%86%E5%B8%83%E5%BC%8F/">分布式</a>, <a href="http://www.linux178.com/tag/%E7%BC%93%E5%AD%98/">缓存</a></p>
    </article>

    
<div id="comments">
        	<h3>已有 2 条评论</h3>
    
    <ol class="comment-list"><li id="comment-2332" class="comment-body comment-parent comment-odd">
    <div class="comment-author">
        <img class="avatar" src="./FastDFS + Nginx 反向代理缓存 安装与配置 - The Soul of Linux_files/b46f25a24f5fffd3ae3f6b8044e71e97" alt="痞子达" width="32" height="32">        <cite class="fn"><a href="http://pizida.com/" rel="external nofollow">痞子达</a></cite>
    </div>
    <div class="comment-meta">
        <a href="http://www.linux178.com/storage/fastdfs-nginx-cache.html/comment-page-1#comment-2332">July 23rd, 2015 at 04:41 pm</a>
            </div>
    <div class="comment-content">
    <p>博主代码高亮是自己写的还是用的插件？</p>    </div>
    <div class="comment-reply">
        <a href="http://www.linux178.com/storage/fastdfs-nginx-cache.html/comment-page-1?replyTo=2332#respond-post-127" rel="nofollow" onclick="return TypechoComment.reply(&#39;comment-2332&#39;, 2332);">回复</a>    </div>
        <div class="comment-children">
        <ol class="comment-list"><li id="comment-2337" class="comment-body comment-child comment-level-odd comment-odd comment-by-author">
    <div class="comment-author">
        <img class="avatar" src="./FastDFS + Nginx 反向代理缓存 安装与配置 - The Soul of Linux_files/8004a0bb1b6090f44ab6aa9245176250" alt="斯巴达克斯" width="32" height="32">        <cite class="fn"><a href="http://www.linux178.com/" rel="external nofollow">斯巴达克斯</a></cite>
    </div>
    <div class="comment-meta">
        <a href="http://www.linux178.com/storage/fastdfs-nginx-cache.html/comment-page-1#comment-2337">July 23rd, 2015 at 10:25 pm</a>
            </div>
    <div class="comment-content">
    <p>是用的插件的</p>    </div>
    <div class="comment-reply">
        <a href="http://www.linux178.com/storage/fastdfs-nginx-cache.html/comment-page-1?replyTo=2337#respond-post-127" rel="nofollow" onclick="return TypechoComment.reply(&#39;comment-2337&#39;, 2337);">回复</a>    </div>
    </li>
</ol>    </div>
    </li>
</ol>
        
    
        <div id="respond-post-127" class="respond">
        <div class="cancel-comment-reply">
        <a id="cancel-comment-reply-link" href="http://www.linux178.com/storage/fastdfs-nginx-cache.html#respond-post-127" rel="nofollow" style="display:none" onclick="return TypechoComment.cancelReply();">取消回复</a>        </div>
    
    	<h3 id="response">添加新评论</h3>
    	<form method="post" action="http://www.linux178.com/storage/fastdfs-nginx-cache.html/comment" id="comment-form" role="form">
                		<p>
                <label for="author" class="required">称呼</label>
    			<input type="text" name="author" id="author" class="text" value="" required="">
    		</p>
    		<p>
                <label for="mail" class="required">Email</label>
    			<input type="email" name="mail" id="mail" class="text" value="" required="">
    		</p>
    		<p>
                <label for="url">网站</label>
    			<input type="url" name="url" id="url" class="text" placeholder="http://" value="">
    		</p>
                		<p>
                <label for="textarea" class="required">内容</label>
                <textarea rows="8" cols="50" name="text" id="textarea" class="textarea" required=""></textarea>
            </p>
    		<p>
                <button type="submit" class="submit">提交评论</button>
            </p>
    	</form>
    </div>
    </div>
</div><!-- end #main-->

<div class="col-mb-12 col-offset-1 col-3 kit-hidden-tb" id="secondary" role="complementary">
        <section class="widget">
		<h3 class="widget-title">最新文章</h3>
        <ul class="widget-list">
            <li><a href="http://www.linux178.com/Java/ftp-sftp-progress.html">使用commons-net包操作FTP和使用jsch包来操作SFTP时如何显示传输进度</a></li>
<li><a href="http://www.linux178.com/Linux-Trouble/jenkins-deploy-qcloud.html">使用Jenkins发布腾讯云项目</a></li>
<li><a href="http://www.linux178.com/python/collect-tomcat-error-log.html">收集Tomcat异常日志并发送邮件</a></li>
<li><a href="http://www.linux178.com/Java/maven-release.html">使用Ant 和 Maven打包发布命令行程序</a></li>
<li><a href="http://www.linux178.com/shell/shell-test.html">shell脚本中的 test 和 [  ] 测试命令</a></li>
<li><a href="http://www.linux178.com/linux/shell-extend.html">shell大括号参数扩展</a></li>
<li><a href="http://www.linux178.com/web/nginx-get-realip.html">nginx获取客户端真实IP地址</a></li>
<li><a href="./FastDFS + Nginx 反向代理缓存 安装与配置 - The Soul of Linux_files/FastDFS + Nginx 反向代理缓存 安装与配置 - The Soul of Linux.html">FastDFS + Nginx 反向代理缓存 安装与配置</a></li>
<li><a href="http://www.linux178.com/perl/perl-get-file-time.html">Perl来获取Linux文件的3个时间</a></li>
<li><a href="http://www.linux178.com/linux/ssh-no-password.html">利用密钥来免密码登录</a></li>
        </ul>
    </section>
    
        <section class="widget">
		<h3 class="widget-title">最近回复</h3>
        <ul class="widget-list">
                            <li><a href="http://www.linux178.com/web/httprequest.html/comment-page-1#comment-2734">Sodo</a>：这是我见过的最完整的一次 HTTP  事务处理过程，配图很直观，很赞.</li>
                    <li><a href="http://www.linux178.com/web/httprequest.html/comment-page-1#comment-2723">MM豆</a>：正在复习考试，然后就看到了这篇文！
敬仰之心犹如滔滔江水呐~~~~
请...</li>
                    <li><a href="http://www.linux178.com/Java/ftp-sftp-progress.html/comment-page-1#comment-2527">于跃</a>：老牛逼了</li>
                    <li><a href="http://www.linux178.com/web/httprequest.html/comment-page-1#comment-2516">andrew</a>：楼主写的很详细，赞</li>
                    <li><a href="http://www.linux178.com/linux/linuxinit.html/comment-page-1#comment-2448">斯巴达克斯</a>：谢谢，请多多交流</li>
                    <li><a href="http://www.linux178.com/linux/linuxinit.html/comment-page-1#comment-2444">鲍伟华</a>：第一次见写的这么详细的Linux技术文档，不得不佩服您，很受用，感谢哈...</li>
                    <li><a href="http://www.linux178.com/nginxlog.html/comment-page-1#comment-2439">斯巴达克斯</a>：已经处理</li>
                    <li><a href="http://www.linux178.com/nginxlog.html/comment-page-1#comment-2432">gamer2013</a>：兄弟.附件的下载403啦.麻烦处理下吧.</li>
                    <li><a href="http://www.linux178.com/web/nginx-get-realip.html/comment-page-1#comment-2431">斯巴达克斯</a>：很抱歉，这种情况没有实验过，按道理来讲应该是可以的。</li>
                    <li><a href="http://www.linux178.com/web/nginx-get-realip.html/comment-page-1#comment-2420">chris</a>：请教一个问题， haproxy 代理， ssl解密在后端(nginx)...</li>
                </ul>
    </section>
    
        <section class="widget">
		<h3 class="widget-title">分类</h3>
        <ul class="widget-list">
            <li><a href="http://www.linux178.com/category/default/">默认分类</a> (0)</li>
<li><a href="http://www.linux178.com/category/linux/">Linux</a> (8)</li>
<li><a href="http://www.linux178.com/category/shell/">Shell脚本</a> (1)</li>
<li><a href="http://www.linux178.com/category/perl/">Perl脚本</a> (3)</li>
<li><a href="http://www.linux178.com/category/python/">Python脚本</a> (2)</li>
<li><a href="http://www.linux178.com/category/web/">WEB</a> (3)</li>
<li><a href="http://www.linux178.com/category/MySQL/">MySQL</a> (1)</li>
<li><a href="http://www.linux178.com/category/Linux-Trouble/">攻城狮的烦恼</a> (2)</li>
<li><a href="http://www.linux178.com/category/Java/">Java</a> (4)</li>
<li><a href="http://www.linux178.com/category/storage/">存储</a> (1)</li>
        </ul>
	</section>
    
        <section class="widget">
		<h3 class="widget-title">归档</h3>
        <ul class="widget-list">
            <li><a href="http://www.linux178.com/2015/08/">August 2015</a></li>
<li><a href="http://www.linux178.com/2015/05/">May 2015</a></li>
<li><a href="http://www.linux178.com/2015/04/">April 2015</a></li>
<li><a href="http://www.linux178.com/2015/03/">March 2015</a></li>
<li><a href="http://www.linux178.com/2015/01/">January 2015</a></li>
<li><a href="http://www.linux178.com/2014/09/">September 2014</a></li>
<li><a href="http://www.linux178.com/2014/08/">August 2014</a></li>
<li><a href="http://www.linux178.com/2014/06/">June 2014</a></li>
<li><a href="http://www.linux178.com/2014/05/">May 2014</a></li>
<li><a href="http://www.linux178.com/2014/04/">April 2014</a></li>
<li><a href="http://www.linux178.com/2014/03/">March 2014</a></li>
<li><a href="http://www.linux178.com/2014/01/">January 2014</a></li>
<li><a href="http://www.linux178.com/2013/12/">December 2013</a></li>
        </ul>
	</section>
    
    	<section class="widget">
		<h3 class="widget-title">其它</h3>
        <ul class="widget-list">
                            <li class="last"><a href="http://www.linux178.com/admin/login.php">登录</a></li>
                        <li><a href="http://www.linux178.com/feed/">文章 RSS</a></li>
            <li><a href="http://www.linux178.com/feed/comments/">评论 RSS</a></li>
            <li><a href="http://www.typecho.org/">Typecho</a></li>
        </ul>
	</section>
     
</div><!-- end #sidebar -->

            
        </div><!-- end .colgroup -->
    </div>
</div><!-- end #body -->

<footer id="footer" role="contentinfo">
    © 2016 <a href="http://www.linux178.com/">The Soul of Linux</a><a href="http://www.miitbeian.gov.cn/">&nbsp;沪ICP备13047964</a>.
</footer><!-- end #footer -->

<script type="text/javascript" src="./FastDFS + Nginx 反向代理缓存 安装与配置 - The Soul of Linux_files/highlight.pack.js"></script><script type="text/javascript">window.onload = function () {
var codes = document.getElementsByTagName("pre"),
    hlNames = {
        actionscript : /^as[1-3]$/i,
        cmake : /^(make|makefile)$/i,
        cs : /^csharp$/i,
        css : /^css[1-3]$/i,
        delphi : /^pascal$/i,
        javascript : /^js$/i,
        markdown : /^md$/i,
        objectivec : /^objective\-c$/i,
        php  : /^php[1-6]$/i,
        sql : /^mysql$/i,
        xml : /^(html|html5|xhtml)$/i
    }, hlLangs = hljs.LANGUAGES;

for (var i = 0; i < codes.length; i ++) {
    var children = codes[i].getElementsByTagName("code"), highlighted = false;

    if (children.length > 0) {
        var code = children[0], className = code.className;

        if (!!className) {
            if (0 == className.indexOf("lang-")) {
                var lang = className.substring(5).toLowerCase(), finalLang;
            
                if (hlLangs[lang]) {
                    finalLang = lang;
                } else {
                    for (var l in hlNames) {
                        if (lang.match(hlNames[l])) {
                            finalLang = l;
                        }
                    }
                }

                if (!!finalLang) {
                    var result = hljs.highlight(finalLang, code.textContent, true);
                    code.innerHTML = result.value;
                    highlighted = true;
                }
            }
        }

        if (!highlighted) {
            var html = code.innerHTML;
            code.innerHTML = html.replace(/<\/?[a-z]+[^>]*>/ig, "");
            hljs.highlightBlock(code, "", false);
        }
    }
}
}</script>
<script type="text/javascript">
var _bdhmProtocol = (("https:" == document.location.protocol) ? " https://" : " http://");
document.write(unescape("%3Cscript src='" + _bdhmProtocol + "hm.baidu.com/h.js%3F9f11c97df4dd607c8f28ef1b5b604234' type='text/javascript'%3E%3C/script%3E"));
</script><script src="./FastDFS + Nginx 反向代理缓存 安装与配置 - The Soul of Linux_files/h.js" type="text/javascript"></script><a href="http://tongji.baidu.com/hm-web/welcome/ico?s=9f11c97df4dd607c8f28ef1b5b604234" target="_blank"><img border="0" src="./FastDFS + Nginx 反向代理缓存 安装与配置 - The Soul of Linux_files/21.gif" width="20" height="20"></a>

</body></html>